How to stop sorting ListView.AlphaSort

Delphi Xe2. Listview (Lv1) with elements of a large list. Lv1 has a standard comparison procedure "TForm1.lv1Compare". Sorting begins with the standard procedure lv1.AlphaSort; Everything works and is sorted fine. Question: how to immediately stop the started sorting if necessary?

Example:

procedure tform1.button1.onclick(..);
begin
lv1.AlphaSort; // start sorting
end;

procedure tform1.button2.onclick(..);
begin
//lv1.StopSort; // stop sorting ???
end;

Or maybe there is some stop command in the OnCompare procedure?

+3
source share
2 answers

A macro is called inside , but I don’t see any mention of how to stop the sorting process in the link (even through the callback function), so I am afraid that this is impossible (at least normal).TListView.AlphaSort ListView_SortItems

Sertac, , OnCompare:

var
  YouWantToAbortSort: Boolean;

procedure TForm1.Button1Click(Sender: TObject);
begin
  YouWantToAbortSort := False;
  ListView1.AlphaSort;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  YouWantToAbortSort := True;
end;

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
  if YouWantToAbortSort then
    Abort;
  // some sorting function here ...
  Application.ProcessMessages;
end;
+4

VirtualTreeView TListView . .

+2

All Articles