In VCL, TTreeNode
has a HasChildren
property:
Indicates whether a node has any children.
HasChildren
is true if the node has subnodes, or false if the node has no subnodes. If ShowButtons
of the tree view is true, and HasChildren
is true, a plus (+) button will appear to the left of the node when it is collapsed, and a minus (-) button will appear when the node is expanded.
Note: If a node has no children, setting HasChildren
to true will show a (+) plus button, but will not add any child nodes and the node cannot be expanded.
So, you can set a node's HasChildren
to true before actual child nodes have been created for it. Then later on, once you have determined whether the node has any actual child nodes, you can reset HasChildren
to false if there are no child nodes present.
Despite what the documentation suggests above, attempting to expand a node that has no child nodes but does have HasChildren
set to true WILL trigger the TTreeView.OnExpanding
event, at least. That is a good place to populate the actual child nodes and update HasChildren
.