[fpc-pascal] Sorting a Stringlist on ValueFromIndex

James Richters james.richters at productionautomation.net
Tue Feb 15 15:55:05 CET 2022


Thanks for the elegant solution Michael, but I'm having some issues implementing it.

I'm getting:

pastep.pas(28651,10) Warning: Function result does not seem to be set

28650  // Custom compare function
28651  function CompareValues(List: TStringList; Index1, Index2: Integer): Integer;
28652  
28653  begin
28654     Result:=CompareText(List.ValueFromIndex[Index1],List.ValueFromIndex[Index2])
28655  end;

pastep.pas(28797,65) Error: Incompatible type for arg no. 1: Got "Pointer", expected "<procedure variable type of function(TStringList;LongInt;LongInt):LongInt;Register>"    

28797   AllLogLastRunStringList.CustomSort(@CompareValues);

The unit I'm putting this in has:
Unit PAStep;
{$Mode TP}{$I-}
{$modeswitch exceptions}
{$R+}

I can fix the first error with:
28654   CompareValues:=CompareText(List.ValueFromIndex[Index1],List.ValueFromIndex[Index2])
{$Mode TP} doesn't like using 'result'

But I have no idea how I could fix the second error.  Any ideas?


James



More information about the fpc-pascal mailing list