TreeFromNode Function

Virtual Tree View

Snow earth.bmp
TreeFromNode Function

General purpose routine to get the tree to which a node belongs.

Pascal
function TreeFromNode(Node: PVirtualNode): TBaseVirtualTree;
Description

For obvious reasons it makes no sense to store the reference to a tree in each node record, but sometimes there might arise the need to know to which tree a node belongs. This is not often the case but is necessary e.g. for optimized moves in drag'n drop or cut'n paste operations. 

 

Each node contains a reference to its parent to allow fast traversal. The hidden root node, however, does not need this reference because it does not have a node parent. Instead it contains the reference of the tree to which it belongs. To determine which node is the root node (when you don't know its tree) a special case of sibling reference is used. Since the root node does neither have a previous nor a next sibling the corresponding pointers are set to the root node, making the root so pointing to itself. This case will never happen in "normal" nodes, so it is a reliable way to detect the root node.

Group
File

VirtualTrees

Links
What do you think about this topic? Send feedback!