Recent

Author Topic: TLazVirtualStringTree.Items  (Read 429 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1696
TLazVirtualStringTree.Items
« on: August 06, 2025, 12:03:14 pm »
There is items property for TTreeview, i.e. I can write

    TreeNode := TreeView.Items[ti]; 

Is there a similar property for TLazVirtualStringTree?

wp

  • Hero Member
  • *****
  • Posts: 13221
Re: TLazVirtualStringTree.Items
« Reply #1 on: August 06, 2025, 12:14:44 pm »
AFAIK, the VirtualTree does not have an Items[] list. You only can iterate over the nodes by methods such as GetNextSibling, GetPrevSibling, GetFirstChild, GetLastChild etc. The normal TTreeView has similar methods as well (accessible from the Items property), and using them is usually preferred over the slower the array-like Items[] property.

egsuh

  • Hero Member
  • *****
  • Posts: 1696
Re: TLazVirtualStringTree.Items
« Reply #2 on: August 06, 2025, 04:50:24 pm »
Actually iterating the nodes of tree structure is not a difficulty. Following algorithm does all.

Code: Pascal  [Select][+][-]
  1. type
  2.     TProcTNOperate = procedure (X: TTreeNode) is nested;
  3.  
  4. implementation
  5.  
  6. procedure IterateTreeNodes (Node: TTreeNode; procOperationOnTreeNode: TProcTNOperate);
  7. begin
  8.     if Node = nil then Exit;
  9.     procOperationOnTreeNode(node);
  10.     IterateTreeNode(Node.getFirstChild);
  11.     IterateTreeNode(Node.GetNextSibling);
  12. end;  
  13.  
  14. begin
  15.     IterateTreeNodes(Treeview.GetFirstChild);
  16. end.
  17.  
  18.  

Simply wondering devising this kine of algorithm deserves the effort, when there is more straightforward way like:

  for ti := 0 to treeview.items.count -1 do procOperateOnTreeNode(treeview.items[ti]);

 

TinyPortal © 2005-2018