Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SortText(Left, Right: TFMXObject): Integer;
- begin
- Result := CompareText((Left as TTreeViewItem).Text, (Right as TTreeViewItem).Text);
- end;
- procedure SortTree(Item: TFmxObject; Comparer: TFmxObjectSortCompare);
- var
- I: Integer;
- begin
- // if we are in the initial call of this procedure, a tree view object is passed
- if Item is TTreeView then
- begin
- // sort the tree's top level nodes first
- Item.Sort(Comparer);
- // then recursively call this procedure for each top level node
- for I := 0 to TTreeView(Item).Count - 1 do
- SortTree(TTreeView(Item).Items[I], Comparer);
- end
- else
- // recursive calls of this procedure are passing tree nodes, which is this case
- begin
- // recursively call this procedure for each of this node's child
- for I := 0 to TTreeViewItem(Item).Count - 1 do
- SortTree(TTreeViewItem(Item).Items[I], Comparer);
- // and sort this node's children
- Item.Sort(Comparer);
- end;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- TreeView1.BeginUpdate;
- try
- SortTree(TreeView1, SortText);
- finally
- TreeView1.EndUpdate;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement