[fpc-pascal] question on docs

Martin Frb lazarus at mfriebe.de
Mon Oct 21 00:32:50 CEST 2024


The compare function is declared right inside the class

   { TFPGList }

   generic TFPGList<T> = class(TFPSList)
   private
     type
       TCompareFunc = function(const Item1, Item2: T): Integer;


"T" is from the generic, so if you specialized with string, then T is 
string.

It is a function, not a method (i.e. not part of a class)


On 21/10/2024 00:17, ppadilcdx--- via fpc-pascal wrote:
> Just tried to compile a short program with that definition of compare: TCompareFunc, and that is the wrong type for TFPGList<String> in my program (yes there is a better class for strings but I just wanted a quick example program to compile). FPC error message says it wants:
> function(const ShortString;const ShortString):LongInt,
> so only two non-pointer input parameters.  Must be another definition somewhere.
>> type TFPSListCompareFunc = function(
>>    Key1: Pointer;
>>    Key2: Pointer
>> ):Integer of object;
>>
>> Two questions.
>> 1) Should TCompareFunc in TFPGList.Sort be one of the above types, or is there another definition somewhere?
>> 2) What is an “Integer of object” in TFPSListCompareFunc? (I expect it to be a typo but then I’m fairly new to free pascal so I might have missed the memo.)
>>
>>

Of object belongs to the function (the entire function declaration 
before), not just the "integer".
So that function must be a method of a class.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241021/58201641/attachment.htm>


More information about the fpc-pascal mailing list