We have some old classes using Contnrs.TObjectList
, and in some cases custom compare-functions are used to sort these lists, using something like this:
procedure TMyClass.SortItems;
function CompareFunction(Item1, Item2: Pointer): Integer;
begin
Result := TSomeItem(Item1).Value - TSomeItem(Item2).Value;
end;
begin
Sort(@CompareFunction);
end;
This code has worked without issues when compiled for Win32, but when we compile it for Win64, we have found that the sorting doesn't work anymore.
I have fixed some of them by using Generics.Collections.TObjectList<T>
instead, and modifying the CompareFunction
and how it is called. So my guess is that it has to do with the way the CompareFunction
is called, by prefixing it with the @
operator, which as I understand, refers to the address of the function.
Why does the code above doesn't work on Win64, and what would be the proper way to fix it?