Method that Implements Indexed Property cannot Contain Parameters Passed by Reference

Description

When the old method of property declaration is used in the signature of a procedure or function that is used to handle access to the property, first variables responsible for property indexes are passed by reference (declared with the Var keyword). In such cases passing parameters by reference is forbidden by specification of the Fore language.

Troubleshooting Tips

Delete the Var keyword specified before the first parameters in the header of procedure or function used by this property.

Example

Class MyClass: Object
    Private PropValue: Array Of String;
    
    Public Constructor Create(Length: Integer);
    Begin
        PropValue := New String[Length];
    End Constructor Create;
    
    Sub Set_Item(Var i: Integer; s: String);
    Begin
        PropValue[i] := s;
    End Sub Set_Item;
    
    Function Get_Item(Var i: Integer): String;
    Begin
        Return PropValue[i];
    End Function Get_Item;
    Public Property Item(i: Integer): String Get Get_Item Set Set_Item;
End Class MyClass;

When the specified code is compiled, the following error is displayed: Method that implements indexed property cannot contain parameters passed by reference. To resolve the error, delete the Var keyword specified before the "i" parameter in the area of declaration of Set_Item procedure and Get_Item function variables.

See also:

Compiler Messages | Error: The <MethodName> Method Cannot Contain Referenced Parameters