[fpc-pascal] TreeView and Nonrecursion

Juha Manninen (gmail) juha.manninen62 at gmail.com
Thu Sep 2 12:14:50 CEST 2010

On Thursday 02 September 2010 00:47:23 José Mejuto wrote:
> You must know at which node a new node must be inserted...

If your input data contains a string which always identifies the parent node 
then you can map the string -> "parent node" and find it later for adding a 
child node.

Pseudo code again:

  ParentNode, Node: TNode;
  Map: TStringHashMap;
  ParentId, Id: string;
  //  get data from somewhere
  ParentId := ...
  Id := ...
  ParentNode := Map[ParentId];
  // This should make Node a root node if ParentNode = nil.
  Node := Tree.AddNode(ParentNode, Id);  // Pseudo syntax.
  Map[Id] := Node;   // Use as parent for following nodes.

If you don't have such ID then you must use recursion.


More information about the fpc-pascal mailing list