开发者

Creating own component based on TreeView (TTreeNode issue)

just need o access to my custom TreeView with this:

MyTreeView1.Selected.MyOwnProperty := 'something';

So, all i want to do is make same component as TreeView is but + i need to add my own pro开发者_高级运维perty to all of the TreeNodes of TreeView.

If I may ask again, can anybody explain me how to use "data property of TTreeNodes to point to an object"? Could anybody explain how to save some information to it (for example name and age) and how to get this information from selected TTreeNode?


At least with XE, you can override the creation of tree nodes with a TTreeView using the OnCreateNodeClass property to create custom TTreeNodes.

For example:

type
  TMyTreeNode = class (TTreeNode)
  //
  end;

procedure TMyForm.OnCreate(Sender: TObject);
begin
  MyTreeView.OnCreateNodeClass := OnCreateNodeClass;
end;

procedure TMyForm.OnCreateNodeClass(Sender: TCustomTreeView; 
  var NodeClass: TTreeNodeClass);
begin
  NodeClass := TMyTreeNode;
end;

You can then subclass TTreeView to change Selected to return your tree node class.


I usually use the data property of TTreeNodes to point to an object that contains the actual data that I'm working with.

That approach encourages separating your model from the GUI, which is a Good Thing.


Manny, if you want to access your custom property at design time you also need to program designtime support for this - custom property editor for Items property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜