[Lazarus] How to pass function method to TList.Sort?
Donald Ziesig
donald at ziesig.org
Wed Dec 9 21:11:05 CET 2015
Hi All!
Is there any way to pass a method function as the Compare parameter to a
TList or is there a work around for it?
There are generics involved so it won't let me access the static symbol
table.
As in:
type
TMyClass = object
fIndex : Integer;
List : array of TList;
function Compare( Item1, Item2 : Pointer) : Longint; // needs
access to fIndex
procedure Sort;
end;
implementation
function TMyClass.Compare( Item1, Item2 : Pointer ) : Longint;
begin
case fIndex of
0: Result := some compare of Item1, Item2;// These compares are
implemented in an object from another unit
1: Result := another compare of Item1, Item2
end;
end;
procedure TMyClass.Sort;
begin
fIndex := 0;
List[fIndex].Sort( @Compare ); // Compilation error, doesn't like
Compare being "of object"
end;
Thanks,
Don Ziesig
More information about the Lazarus
mailing list