Im trying to make my custom TTreeNode Class
for example
TCustomTreeNode = class(TTreeNode)
private
public
Comment:string;
end;
and i create and add the node in the tree view like this:
var
NewCustomTreeNode:TCustomTreeNode;
begin
NewCustomTreeNode:= TCustomTreeNode.Create(TreeView.Items);
NewCustomTreeNode.Comment:='blqblq';
TreeView.Items.AddChild(NewCustomTreeNode,'NodeText');
and when i try to access the custom created tree nodes error pops up. For example i do like this:
TCustomTreeNode(TreeNode).Comment:='asdadssadas';
plase help
The problem with your code is that the call to
AddChildresults in the tree view creating a new node. And since you didn’t tell the tree view to create a node of your sub-class it creates a plainTTreeNode. And then when you try to cast it to aTCustomTreeNode, the world ends.You need to use the
OnCreateNodeClassmethod to make sure that the tree view is able to create new nodes. Like this:I can’t claim to being the world’s greatest expert on Delphi tree views but in my experience you never create a tree node yourself. You should always call one of the
AddXXXmethods onTTreeView.Itemsto create new nodes.