[fpc-devel] Is that supposed to work: property with "[var index: TFoo]" ?
Sven Barth
pascaldragon at googlemail.com
Fri Jun 28 07:39:10 CEST 2019
Am 27.06.2019 um 21:09 schrieb Martin:
> The below compiles, and writes
> 1 2
>
> Are indexes to properties intentionally allowed to take "var param"?
> Btw it even compiles with an "out" param.
>
>
> program Project1;
> type
>
> { TFoo }
>
> TFoo = class
> private
> function GetFoo(var AIndex: Integer): Integer;
> public
> property Foo[var AIndex: Integer]: Integer read GetFoo;
> end;
>
> { TFoo }
>
> function TFoo.GetFoo(var AIndex: Integer): Integer;
> begin
> Result := AIndex;
> AIndex := AIndex+1;
> end;
>
> var a,i: integer;
> f: TFoo;
> begin
> f := TFoo.Create;
> i := 1;
> a := f.Foo[i];
> writeln(a,' ',i);
> readln;
> end.
>
I just tested with Delphi and it works there as well. So contrary to
what we thought this does not seem to be a bug...
Regards,
Sven
More information about the fpc-devel
mailing list