[fpc-pascal] Error: Argument cannot be assigned to

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Jun 4 16:16:04 CEST 2023


On Sun, 4 Jun 2023 16:04:48 +0300
Juha Manninen via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:

> Why the following code fails to compile?
> 
> type
>   TMyRec = record
>     ss: String;
>     ii: Integer;
>   end;
>   TMyClass = class
>   private
>     fName: String;
>     fRecInstance: TMyRec;
>   property
>     RecInstance: TMyRec read fRecInstance;// write fRecInstance;
>   end;
> var
>   MyObj : TMyClass;
> begin
>   MyObj := TMyClass.Create;
>   MyObj.RecInstance.ii := 123;
>   MyObj.Free;
> end.
> 
> Access through property seems to be the problem. Accessing
> fRecInstance directly works.

Correct. Property RecInstance is read only.

Mattias


More information about the fpc-pascal mailing list