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

Martin Frb lazarus at mfriebe.de
Sun Jun 4 18:10:14 CEST 2023


On 04/06/2023 17:49, Martin via fpc-pascal wrote:
> On 04/06/2023 15:04, Juha Manninen via fpc-pascal wrote:
>> Why the following code fails to compile?
>> MyObj.RecInstance.ii := 123;
> Technically you can modify the members of the temp record (just to 
> have the work thrown away afterwards).
>
> So I guess the compiler forbids it, because the only case it would 
> ever be done is: by mistake.

Btw, this works (or actually not, it works wrong)

   with  MyObj.RecInstance do {begin} ii := 123; {end;}

Now you could do some work with the temp result, and have it trashed at 
the end of the "with" block.

However, fpc incorrectly changes the value in the original record.
Yet, don't use it. It will (likely) change, and stop working. (or work 
correctly, changing the temp value only).


More information about the fpc-pascal mailing list