[fpc-devel] Is that supposed to work: property with "[var index: TFoo]" ?
Martin Frb
lazarus at mfriebe.de
Sun Jun 30 00:02:50 CEST 2019
On 29/06/2019 23:43, Sven Barth via fpc-devel wrote:
> Am 28.06.2019 um 10:39 schrieb Martin Frb:
>> What does Delphi do with
>>
>> property Foo[AIndex: Integer; BIndex: Integer = 0]: Integer read
>> GetFoo;
>> Because FPC rejects this one. (And IMHO rightfully so)
>
Hope this madness can be avoided in fpc....
> The following also fails:
> === code begin ===
>
> function GetFoo(AIndex: Integer; BIndex: Integer): Integer;
> property Foo[AIndex: Integer; BIndex: Integer = 0]: Integer read GetFoo;
Good
> 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[] // ????
> As does this:
> === code begin ===
>
> function GetFoo(AIndex: Integer; BIndex: Integer = 0): Integer;
> property Foo[AIndex: Integer; BIndex: Integer]: Integer read GetFoo;
This is ok.
GetFoo can be called directly.
So long, as the property will fail, if called with only one index.
More information about the fpc-devel
mailing list