[fpc-devel] Is that supposed to work: property with "[var index: TFoo]" ?

Martin Frb lazarus at mfriebe.de
Fri Jun 28 01:16:47 CEST 2019


On 28/06/2019 00:09, Ben Grasset wrote:
> On Thu, Jun 27, 2019 at 4:12 PM Martin <fpc at mfriebe.de 
> <mailto:fpc at mfriebe.de>> wrote:
>
>     Are indexes to properties intentionally allowed to take "var param"?
>     Btw it even compiles with an "out" param.
>
>
> "Var" and "Out" seem bad, although I've always though that "Constref" 
> *should* be allowed.
>

Most property index are simple types. So you would not need it.

But *** hypothetically speaking ***  constref (and const too) could be 
given in the getter, but not in the property
TFoo = class
   private
     function GetFoo(constref AIndex: Integer): Integer;
   public
     property Foo[AIndex: Integer]: Integer read GetFoo;
   end;
The compiler woull simply (nothing is ever simple ;) ) need to know that 
the signature is still valid, even with the constref.
Of course the compiler accepts any data type as valid for the index. So 
you could declare a big record for the index, and argue for constref. I 
don't really think it is needed.


Another one, that arises suspicion for its validity: open arrays. They 
can only be declared in parameter lists for procedures and functions.
Oh and in properties:
TFoo = class
   private
     function GetFoo(AIndex: array of Integer): Integer;
   public
     property Foo[AIndex: array of Integer]: Integer read GetFoo;
   end;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190628/58b3c9f0/attachment.html>


More information about the fpc-devel mailing list