Project source
Form source (Pascal)
Form source (DFM)
Project source: RichEditTest.dpr |
program RichEditTest; uses Forms, fmRichEdit in 'fmRichEdit.pas' {Form1}; {$R *.RES} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.Back to top |
Form source: fmRichEdit.pas |
unit fmRichEdit; { UnitOOPS OLE Drag and Drop Components - Example Form for RTF drop into TRichEdit demonstration. Last modified: 08/28/98} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, uoole, uoUtil, StdCtrls, ExtCtrls, ComCtrls; type TForm1 = class(TForm) Panel1: TPanel; Panel2: TPanel; Label1: TLabel; UOTextTarget1: TUOTextTarget; RichEdit1: TRichEdit; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; procedure UOTextTarget1Drop(Sender: TObject; Acceptor: TWinControl; const dropText: String; X, Y: Integer); procedure FormCreate(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure UOTextTarget1DragOver(Sender: TObject; effect: TDropEffect; X, Y: Integer); private { Private declarations } function CharPosInRichEdit(aRichEdit: TRichEdit; X, Y: integer): integer; function PixelPosInRichEdit(aRichEdit: TRichEdit; aCharPos: integer): TPoint; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.UOTextTarget1Drop(Sender: TObject; Acceptor: TWinControl; const dropText: String; X, Y: Integer); var doInsert: boolean; begin // We've got the dropped text. // If it's RTF, use the utility function. // If it's plain text, use standard stuff. doInsert := CheckBox3.Checked; // Are we inserting or appending? // addContentToRichEdit is in the uoUtil unit. It allows you to add text // to a TRichEdit, accepting as input either plain text or RTF. The third // parameter is true for RTF, false otherwise. The fourth parameter is // true to insert the content at the cursor position, false to append it. // If you want to replace the contents of the RichEdit, first clear them. case (Sender as TUOTextTarget).droppedTextFormat of // dtfRichText: // It's RTF - insert it addContentToRichEdit(dropText, RichEdit1, true, doInsert); // Insert RTF dtfText: // It's plain text - insert it addContentToRichEdit(dropText, RichEdit1, false, doInsert); // Insert text end; // case end; procedure TForm1.FormCreate(Sender: TObject); begin // Initial control settings CheckBox1.Checked := UOTextTarget1.AcceptText; CheckBox2.Checked := UOTextTarget1.AcceptRichText; // No compiler warnings, pleaseBack to top |
Form source: fmRichEdit.dfm |
object Form1: TForm1 Left = 311 Top = 283 Width = 437 Height = 270 Caption = 'Rich Edit control example' Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object Panel1: TPanel Left = 0 Top = 68 Width = 429 Height = 175 Align = alClient BevelOuter = bvNone BorderWidth = 3 Caption = 'Panel1' TabOrder = 0 object RichEdit1: TRichEdit Left = 3 Top = 3 Width = 423 Height = 169 Align = alClient ScrollBars = ssBoth TabOrder = 0 WordWrap = False end end object Panel2: TPanel Left = 0 Top = 0 Width = 429 Height = 68 Align = alTop BevelOuter = bvNone BorderWidth = 3 TabOrder = 1 object Label1: TLabel Left = 3 Top = 3 Width = 423 Height = 30 AutoSize = False Caption = 'Drop plain text or rich text onto this TRichEdit control. We'#39've' + ' overridden the default TRichEdit drag/drop handling to get more' + ' control.' WordWrap = True end object CheckBox1: TCheckBox Left = 17 Top = 33 Width = 129 Height = 17 Caption = 'Accept plain text' TabOrder = 0 OnClick = CheckBox1Click end object CheckBox2: TCheckBox Left = 17 Top = 50 Width = 151 Height = 17 Caption = 'Accept rich text (RTF)' TabOrder = 1 OnClick = CheckBox1Click end object CheckBox3: TCheckBox Left = 192 Top = 33 Width = 97 Height = 17 Caption = 'Insert at caret' State = cbChecked TabOrder = 2 end end object UOTextTarget1: TUOTextTarget AcceptorControl = RichEdit1 AcceptTextFormats = [dtfFiles] OnDragOver = UOTextTarget1DragOver OnDrop = UOTextTarget1Drop Left = 40 Top = 105 end endBack to top |