TTreeconnection

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

TTreeconnection

Post by BE » Tue Apr 25, 2006 3:19 am

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

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Tue Apr 25, 2006 7:02 pm

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;

Post Reply