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

Michael Van Canneyt michael at freepascal.org
Sun Jun 30 10:17:03 CEST 2019



On Sun, 30 Jun 2019, Sven Barth via fpc-devel wrote:

> Am 30.06.2019 um 00:02 schrieb Martin Frb:
>>> However this works:
>>> === code begin ===
>>>
>>> function GetFoo(AIndex: Integer; BIndex: Integer = 0): Integer;
>>> property Foo[AIndex: Integer; BIndex: Integer = 0]: Integer read GetFoo;
>> Ouch
>> What then about
>>   function GetFoo(AIndex: Integer = 0): Integer;
>>   property Foo[AIndex: Integer = 0]: Integer read GetFoo;
>> And if it compiles, which of those can you call
>>   Obj.Foo
>>   Obj.Foo[]
>> And what if you make that default property....
>>   Obj[] // ????
>
> Those all don't compile. Even using my example above "Foo[42]" does not 
> compile either, so while a default parameter can be declared the 
> compiler won't allow the default parameters to be left out in the index 
> clause.
>
> Maybe we should forbid default parameters in the index clause in 
> non-Delphi modes so that it's clear that this won't work?

It has no sense allowing them to be declared if they don't work, so yes.
Either that or allow them to be omitted.

Michael.


More information about the fpc-devel mailing list