Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop sorting ListView.AlphaSort

Delphi Xe2. Listview (Lv1) with the big list items. Lv1 have standart compare procedure "TForm1.lv1Compare". Sorting is started by standard procedure lv1.AlphaSort; All works and is sorted normally. A question: how immediately to stop the started sorting in case of need?

example:

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

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

Or can be in procedure OnCompare there is any command of a stop?

like image 883
Gu. Avatar asked Dec 13 '25 15:12

Gu.


1 Answers

Inside of the TListView.AlphaSort the ListView_SortItems macro is being called but I can't see any mention about how to stop the sorting process in the reference (even through the callback function), so I'm afraid this is not possible (at least regular way).

Like Sertac suggested in his comment, as one possible workaround might be to raise the silent exception inside of the OnCompare event:

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;
like image 173
6 revsTLama Avatar answered Dec 15 '25 06:12

6 revsTLama