Unit1.cpp
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:3k
源码类别:

RichEdit

开发平台:

Delphi

  1. /*============================} unit Unit1; {==================================}
  2. { Main properties were set at design time:                                     }
  3. { Table1->TableName           = "SampleTable.db"; // Paradox table             }
  4. { Table1->ReadOnly            = false;                                         }
  5. { DataSource1->Dataset        = Table1;                                        }
  6. { DBNavigator1->DataSource    = DataSource1;                                   }
  7. { DBEdit1->DataSource         = DataSource1;                                   }
  8. { DBRichView1->DataSource     = DataSource1;                                   }
  9. { DBRichView1->Style          = RVStyle1;                                      }
  10. { DBEdit1->DataField          = "Caption";  // Alphanumeric field              }
  11. { DBRichViewEdit1->DataField  = "RVFField"; // Binary field                    }
  12. { nbEdit was removed from DBNavigator1->VisibleButtons (because of autoedit)   }
  13. {------------------------------------------------------------------------------}
  14. { Note: changes after last posting are not saved when exiting application.     }
  15. {=============================================================================*/
  16. #include <vclvcl.h>
  17. #pragma hdrstop
  18. #include "Unit1.h"
  19. #include "Unit2.h"
  20. //---------------------------------------------------------------------------
  21. #pragma link "DBRV"
  22. #pragma link "RichView"
  23. #pragma link "RVScroll"
  24. #pragma link "RVStyle"
  25. #pragma resource "*.dfm"
  26. TForm1 *Form1;
  27. //---------------------------------------------------------------------------
  28. __fastcall TForm1::TForm1(TComponent* Owner)
  29.     : TForm(Owner)
  30. {
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TForm1::FormCreate(TObject *Sender)
  34. {
  35.   // Opening table...
  36.   Table1->DatabaseName = ExtractFilePath(Application->ExeName);
  37.   Table1->Open();
  38.   RVStyle1->TextStyles->Items[1] = RVStyle1->TextStyles->Items[0];
  39.   RVStyle1->TextStyles->Items[1]->Style << fsBold;
  40. }
  41. //---------------------------------------------------------------------------
  42. void TForm1::UpdateStatusLabel()
  43. {
  44.  if (Table1->RecordCount==0)
  45.     Label3->Caption = "(empty)";
  46.   else if (Table1->RecNo<1)
  47.     Label3->Caption = "(new)";
  48.   else
  49.     Label3->Caption = Format("Record %d of %d", ARRAYOFCONST(((int)Table1->RecNo, (int)Table1->RecordCount)));
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TForm1::DataSource1DataChange(TObject *Sender, TField *Field)
  53. {
  54.   UpdateStatusLabel();
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::Button1Click(TObject *Sender)
  58. {
  59.   // See Unit2.pas
  60.   Form2->SetField("RVFField",Table1);
  61.   Form2->ShowModal();
  62. }
  63. //---------------------------------------------------------------------------