1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| function TForm16.SortText(Left, Right: TFMXObject): Integer;
var l,r : integer;
begin
l:=Left.Tag;
r:=Right.Tag;
Result := l-r; //CompareText((Left as TTreeViewItem).Text, (Right as TTreeViewItem).Text);
end;
procedure TForm16.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; |
Partager