It does not work in Delphi either, unless that comparato method would be
class static function, which si not a method at all, but a global function hidden inside the class namespace.
Delphi XE2 error is attached.
Just like
bytebites said - make this functon global.
The parameters of the declaration are 3 of them, the call contains only one parameter.
I think you are wrong here, twice.
- the call to TStringList.CustomSort has only one single parameter - the functon to be called by StringList. A pointer to a function with specific signaure. Read any Pascal tutorial about procedure types.
- your function TFrame_Korrelationen.StringListSortComparefn2(List: TStringList; Index1, Index2: Integer): Integer; does not have three paramaeters, it had FOUR parameters. You forgot about Self, which is a parameter too, albeit "hidden" or "invisible" one. This 4th paramneter is exactly why TStringList can not call this your function.
It is possible, though, that you used not the Delphi stock TStringList, but some extended, 3rd party string list, that has a number of overloaded
CustomSort functions consuming many different comparer types, including the 4-parameter
function (x, y, z):T OF OBJECT datatype
It is also possible that recent Delphi would re-define
TStringListSortCompare datatypeto be
REFERENCE TO function(x,y,z):T. This would work slower but be more flexible.
I wonder if FPC's stock
TStringList could be extended to have two more
CustomSort methods, including
function(string,string) and
function(stringlist, integer, integer) of object comparators.
While it would make things a bit slower i do not think performance is very pressing concern for TStringList