برای داشتن ایتم های اضافی در درخت دلفی میتوان با نوشتن کد زیر ان را شخصی سازی کرد
type
TCustomTreeNode = class(TTreeNode)
protected
procedure Assign(Source: TPersistent); override;
public
Comment: string;
end;
procedure TCustomTreeNode.Assign(Source: TPersistent);
begin
if Source is TCustomTreeNode then
Comment := TCustomTreeNode(Source).Comment;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
NewNode: TCustomTreeNode;
begin
NewNode := TreeView1.Items.Add(nil, 'Node1') as TCustomTreeNode;
NewNode.Comment := 'A comment';
NewNode := TreeView1.Items.Add(nil, 'Node2') as TCustomTreeNode;
NewNode.Comment := 'Another comment';
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
Node: TCustomTreeNode;
begin
Node := TreeView1.Selected as TCustomTreeNode;
if Assigned(Node) then
ShowMessage(Node.Comment);
end;
procedure TForm1.TreeView1CreateNodeClass(Sender: TCustomTreeView; var NodeClass: TTreeNodeClass);
begin
NodeClass := TCustomTreeNode;
end;