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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With