Page 1 of 1
TTreeconnection
Posted: Tue Apr 25, 2006 3:19 am
by 9339885
Hi
How can I add a derived class of TTreeConnection such as TMyTreeConnection in to the Connection list. I'd like to put more features into TMyTreeConnection, but can not find a way to add TMyTreeConnection.
Thanks
-Bill
Posted: Tue Apr 25, 2006 7:02 pm
by Tom
Hi,
You can set the ConnectionClass property of the GlobalFormat to your TMyConnection.
Have a look at the following code:
Code: Select all
TMyConnection = class(TTreeConnection)
public
constructor Create(AOwner:TComponent); override;
end;
TForm1 = class(TForm)
Tree1: TTree;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TMyConnection.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
self.Border.Color := clBlue;
self.SimpleText := 'I am a TMyTreeConnection';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tree1.GlobalFormat.ConnectionClass := TMyConnection;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
rootNode: TTreeNodeShape;
begin
rootNode := Tree1.AddRoot('Tree with TMyTreeConnections');
for i := 0 to 10 do
begin
rootNode.AddChild('Child '+IntToStr(i));
end;
end;