How to use TList.Sort(Compare)?
Hello,
As a member function of objects TList, there is a description in on-line
help file as following between ==, but no Example! Could you write a
short piece of Example for me?
I wrote a failed routing as below between --. Can you figure out how to
assign the CompareTop function to Sort()? Thank you in advance.
Chen Xun
=============================================== Delphi 2.0 On-Line Help
Declaration
procedure Sort(Compare: TListSortCompare);
TListSortCompare = function (Item1, Item2: Pointer): Integer;
Description
The Sort method performs a Quick Sort on the list based on the return
results of Compare. Compare will return < 0 if Item1 is less and Item2,
0 if they are equal and > 0 if Item1 is greater than Item2.
=======================================================================
----------------------------------------------------- My failed routing
type
TMyClass = Class
private
RectList: TList;
procedure SortListByTop;
function CompareTop(Item1, Item2: Pointer): integer;
end;
implementation
procedure TMyClass.SortListByTop;
begin
RectList := GetRectList;
RectList.Sort(CompareTop); <- ?????????????????
end;
function TMyClass.CompareTop(Item1, Item2: Pointer): Integer;
begin
result := TRect(Item1).Top - TRect(Item2).Top;
end;
-----------------------------------------------------------------------