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

Martin fpc at mfriebe.de
Thu Jun 27 21:09:07 CEST 2019


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.



More information about the fpc-devel mailing list