[fpc-devel] Is that valid? property using function with extra args...

Martin me at mfriebe.de
Sun Jun 23 00:39:38 CEST 2024


Below compiles (3.2.3). Should it?

Note the extra argument in "GetFoo". It only works because it has a default.

program Project1;
type
   tf = class
   private
     function GetFoo(AIndex: Integer; b: integer = 2): char;
   public
     property Foo: char index 1 read GetFoo;
   end;

function tf.GetFoo(AIndex: Integer; b: integer): char;
begin
end;

begin
end.


---------
On that note,
if instead the correct amount of params was given:

     function GetFoo(AIndex: Integer= 2): char;

But with a default, should that work.
It does, and IMHO it is ok to work.

If used by the property, then a value is always given and the default 
never matters.
But if called directly, the default can be used.


More information about the fpc-devel mailing list