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

RichEdit

开发平台:

Delphi

  1. /*=============================================================================}
  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. { DBRichViewEdit1->DataSource = DataSource1;                                   }
  9. { DBRichViewEdit1->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. { DBRichViewEdit has data-aware features that require no code to use           }
  15. { (just like most of other Delphi db controls).                                }
  16. { Some more event handlers are needed for advanced RVF features, such as saving}
  17. { "bullets" and "hotspots". There is no difference here with saving/loading    }
  18. { RVF files.                                                                   }
  19. { The code below opens table, updates label displaying record number,          }
  20. { provides "bold" button functionality.                                        }
  21. {------------------------------------------------------------------------------}
  22. { Note: changes after last posting are not saved when exiting application.     }
  23. {=============================================================================*/
  24. #include <vclvcl.h>
  25. #pragma hdrstop
  26. #include "Unit1.h"
  27. //---------------------------------------------------------------------------
  28. #pragma link "DBRV"
  29. #pragma link "RVEdit"
  30. #pragma link "RichView"
  31. #pragma link "RVScroll"
  32. #pragma link "RVStyle"
  33. #pragma resource "*.dfm"
  34. TForm1 *Form1;
  35. //---------------------------------------------------------------------------
  36. __fastcall TForm1::TForm1(TComponent* Owner)
  37.     : TForm(Owner)
  38. {
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall TForm1::FormCreate(TObject *Sender)
  42. {
  43.   // Opening table...
  44.   Table1->DatabaseName = ExtractFilePath(Application->ExeName);
  45.   Table1->Open();
  46.   // For demonstrating rich text ability of TDBRichViewEdit,
  47.   // we've added "Bold" button. It will switch the 0-th and the 1-st styles.
  48.   // Making 1-st text style a bold copy of 0-th style...
  49.   RVStyle1->TextStyles->Items[1] = RVStyle1->TextStyles->Items[0];
  50.   RVStyle1->TextStyles->Items[1]->Style << fsBold;
  51. }
  52. //---------------------------------------------------------------------------
  53. void TForm1::UpdateStatusLabel()
  54. {
  55.   if (Table1->RecordCount==0)
  56.     Label3->Caption = "(empty)";
  57.   else if (Table1->RecNo<1)
  58.     Label3->Caption = "(new)";
  59.   else
  60.     Label3->Caption = Format("Record %d of %d", ARRAYOFCONST(((int)Table1->RecNo, (int)Table1->RecordCount)));
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::DataSource1DataChange(TObject *Sender, TField *Field)
  64. {
  65.   UpdateStatusLabel();    
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::DBRichViewEdit1CurTextStyleChanged(TObject *Sender)
  69. {
  70.   SpeedButton1->Down = DBRichViewEdit1->CurTextStyleNo!=0;    
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
  74. {
  75.   // switching 1-st and 0-th styles
  76.   if (SpeedButton1->Down)
  77.     DBRichViewEdit1->ApplyTextStyle(1);
  78.   else
  79.     DBRichViewEdit1->ApplyTextStyle(0);
  80. }
  81. //---------------------------------------------------------------------------