Reputation: 1957
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?
Upvotes: 3
Views: 667
Reputation: 76663
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;
Upvotes: 4
Reputation: 3706
Use VirtualTreeView instead of TListView and do the sort of your data in another thread. Then you'll have an ability to stop it any time.
Upvotes: 2