The following method calls itself recursively to traverse the items in a tree, applying code to each tree item encountered:

function traverseTree( tRoot, kProcess )

   local t 

   t = tRoot.firstChild // Start with first item in the tree 

   do while t # null // if any, and repeat until done 

      kProcess( t ) // Process each tree item 

      class::traverseTree( t, kProcess ) // Call recursively for sub-tree 

      t := t.nextSibling // Next item at same level 

   enddo 

The following code calls the method to traverse the entire tree treeview1 and display each item’s basic properties:

function dumpTreeButton_onClick

   class::traverseTree( form.treeview1, {|t|; ? t.level, t.checked, t.text} )