Thema: Delphi Count tree root nodes

Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Count tree root nodes

  Alt 26. Aug 2014, 10:43
You are right that this is very slow and the documentation also stated this Delphi-Referenz durchsuchenTTreeView.Items
http://docwiki.embarcadero.com/Libraries/XE6/en/Vcl.ComCtrls.TTreeView.Items

Note: Accessing tree view items by index can be time-intensive, particularly when the tree view contains many items. For optimal performance, try to design your application so that it has as few dependencies on the tree view's item index as possible.

But there are some methods to walk through the tree:

Get the very first node by calling MyNode := MyTreeView.Items[0]; .
Walk through the tree until you get the desired level with Delphi-Referenz durchsuchenTTreeNode.Next
Delphi-Quellcode:
while Assigned( MyNode ) and ( MyNode.Level <> ALevel ) do
  MyNode := MyNode.GetNext;
Once you got the node at the desired level you can step through all nodes on this level with Delphi-Referenz durchsuchenTTreeNode.GetNextSibling
Delphi-Quellcode:
while Assigned( MyNode ) do
  MyNode := MyNode.GetNextSibling;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat