Author: Tomas Rutkauskas
With my colleagues, we tried to implement a checkbox object into Rich Edit.
Is that possible anyway?
Answer:
This seems not possible from within the IDE/ Object Inspector. However, if you
create the checkbox instance dynamically (at run-time), then it works as expected.
For the following example, create a new form, drop a TRichEdit on it and create the
checkbox in the FormCreate() event.
The button event handler code moves the RichEdit control at run-time around to
demonstrate that the checkbox really is its child.
1 unit fMain;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ComCtrls;
8
9 type
10 TForm1 = class(TForm)
11 RichEdit1: TRichEdit;
12 Button1: TButton;
13 procedure Button1Click(Sender: TObject);
14 procedure FormCreate(Sender: TObject);
15 private
16 { private declarations }
17 public
18 { public declarations }
19 end;
20
21 var
22 Form1: TForm1;
23
24 implementation
25
26 {$R *.DFM}
27
28 procedure TForm1.Button1Click(Sender: TObject);
29 begin
30 RichEdit1.Left := 100 - RichEdit1.Left;
31 end;
32
33 procedure TForm1.FormCreate(Sender: TObject);
34 var
35 cb: TCheckBox;
36 begin
37 RichEdit1.Left := 20;
38
39 cb := TCheckBox.Create(RichEdit1);
40 // do not forget to set the
41 cb.Parent := RichEdit1;
42 cb.Left := 30;
43 cb.Top := 30;
44 cb.Caption := 'my checkbox';
45 end;
46
47 end.
|