Thema: Delphi Count tree root nodes

Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Count tree root nodes

  Alt 26. Aug 2014, 10:01
Delphi-Version: XE5
Today I need to know how many root nodes (I mean without parent node) has my tree. I wrote this:

Delphi-Quellcode:
function CountTreeNodes(ATree: TTreeView; ALevel: Word): Integer;
var
  I: integer;
begin
  Result := 0;

  for I := 0 to ATree.Items.Count - 1 do
  begin
    if ALevel = ATree.Items[I].Level then
      Inc(Result)
    ;
  end;
end;

Count := CountTreeNodes(Tree, 0);
This is working, but is quite lame IMO - function will be slow and sloow and slooow if many nodes on tree. Is possible to do it in pro mode?
  Mit Zitat antworten Zitat