“Left side cannot be assigned to” for record type properties in Delphi

Since “Rec” is a property, the compiler treats it a little differently because it has to first evaluate the “read” of the property decl. Consider this, which is semantically equivalent to your example:

...
property Rec: TRec read GetRec write FRec;
...

If you look at it like this, you can see that the first reference to “Rec” (before the dot ‘.’), has to call GetRec, which will create a temporary local copy of Rec. These temporaries are by design “read-only.” This is what you’re running into.

Another thing you can do here is to break out the individual fields of the record as properties on the containing class:

...
property RecField: Integer read FRec.A write FRec.A;
...

This will allow you to directly assign through the property to the field of that embedded record in the class instance.

Leave a Comment