Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-10

question on docs

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

I’m a little confused by some references in the docs. Hopefully I can explain it clearly.

Looking at TFPGList in fgl. The Sort method refers to a TCompareFunc (it does not link to its definition). TFPGList says it’s methods are the same as TFPSList or classes.TFPList. So looking in these two other classes their Sort methods refer to TFPSListCompareFunc (in fgl) and TListSortCompare (in classes), respectively.

type TListSortCompare = function(
  Item1: Pointer;
  Item2: Pointer
):Integer;
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.)

Thanks,
Pete

Reply by email

Peter B
to Unknown author
ppadilcdx--- wrote 24 lines
I’m a little confused by some references in the docs. Hopefully I can explain it clearly. Looking at TFPGList in fgl. The Sort method refers to a TCompareFunc (it does not link to its definition). TFPGList says it’s methods are the same as TFPSList or classes.TFPList. So looking in these two other classes their Sort methods refer to TFPSListCompareFunc (in fgl) and TListSortCompare (in classes), respectively. type TListSortCompare = function( Item1: Pointer; Item2: Pointer ):Integer; 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.) Thanks, Pete _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

For question 1, I find the definition of TCompareFunc here https://www.freepascal.org/docs-html/fcl/bufdataset/tcomparefunc.html

Reply by email

Unknown author
to Peter B

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.

Show quoted text 37 lines
On Oct 20, 2024, at 2:38 PM, Peter B via fpc-pascal wrote: On 20/10/2024 22:17, ppadilcdx--- via fpc-pascal wrote: > I’m a little confused by some references in the docs. Hopefully I can explain it clearly. > > Looking at TFPGList in fgl. The Sort method refers to a TCompareFunc (it does not link to its definition). TFPGList says it’s methods are the same as TFPSList or classes.TFPList. So looking in these two other classes their Sort methods refer to TFPSListCompareFunc (in fgl) and TListSortCompare (in classes), respectively. > > type TListSortCompare = function( > Item1: Pointer; > Item2: Pointer > ):Integer; > > 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.) > > Thanks, > Pete > > _______________________________________________ > fpc-pascal maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal For question 1, I find the definition of TCompareFunc here https://www.freepascal.org/docs-html/fcl/bufdataset/tcomparefunc.html _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Martin Frb
to Unknown author

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)

ppadilcdx--- wrote 13 lines
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.

Reply by email

Unknown author
to Martin Frb

Ah, Ok thanks!

Show quoted text 38 lines
On Oct 20, 2024, at 3:32 PM, Martin Frb via fpc-pascal wrote: 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. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email