unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts,
FMX.TreeView;
type
TForm1 =
class(TForm)
TreeView1: TTreeView;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
function CompareAsc(Item1, Item2: TFmxObject): Integer;
function CompareDesc(Item1, Item2: TFmxObject): Integer;
implementation
{$R *.fmx}
function CompareAsc(Item1, Item2: TFmxObject): Integer;
begin
Result := Item2.Tag - Item1.Tag;
end;
function CompareDesc(Item1, Item2: TFmxObject): Integer;
begin
Result := Item1.Tag - Item2.Tag;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TreeViewItem: TTreeViewItem;
i: Integer;
begin
for i := 0
to 9
do
begin
TreeViewItem := TTreeViewItem.Create(TreeView1);
TreeViewItem.Parent := TreeView1;
TreeViewItem.Text := i.tostring;
TreeViewItem.Tag := i;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//TreeView1.BeginUpdate;
TreeView1.Sort(CompareAsc);
//TreeView1.EndUpdate;
TreeView1.Repaint;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//TreeView1.BeginUpdate;
TreeView1.Sort(CompareDesc);
//TreeView1.EndUpdate;
TreeView1.Repaint;
end;
end.