Advertisement
TLama

Untitled

Oct 23rd, 2014
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.13 KB | None | 0 0
  1. function SortText(Left, Right: TFMXObject): Integer;
  2. begin
  3.   Result := CompareText((Left as TTreeViewItem).Text, (Right as TTreeViewItem).Text);
  4. end;
  5.  
  6. procedure SortTree(Item: TFmxObject; Comparer: TFmxObjectSortCompare);
  7. var
  8.   I: Integer;
  9. begin
  10.   // if we are in the initial call of this procedure, a tree view object is passed
  11.   if Item is TTreeView then
  12.   begin
  13.     // sort the tree's top level nodes first
  14.     Item.Sort(Comparer);
  15.     // then recursively call this procedure for each top level node
  16.     for I := 0 to TTreeView(Item).Count - 1 do
  17.       SortTree(TTreeView(Item).Items[I], Comparer);
  18.   end
  19.   else
  20.   // recursive calls of this procedure are passing tree nodes, which is this case
  21.   begin
  22.     // recursively call this procedure for each of this node's child
  23.     for I := 0 to TTreeViewItem(Item).Count - 1 do
  24.       SortTree(TTreeViewItem(Item).Items[I], Comparer);
  25.     // and sort this node's children
  26.     Item.Sort(Comparer);
  27.   end;
  28. end;
  29.  
  30. procedure TForm1.Button1Click(Sender: TObject);
  31. begin
  32.   TreeView1.BeginUpdate;
  33.   try
  34.     SortTree(TreeView1, SortText);
  35.   finally
  36.     TreeView1.EndUpdate;
  37.   end;
  38. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement