Delphi "E2064 Left side cannot be assigned" an error occurred while updating the project from 2009 to XE

I am reading this question that was discussing the same problem , anyway, I was able to do it in Delphi 2009, and it was not possible since I was upgraded to XE.

I am inserting a simple example of dummy code here: this one compiles in 2009 and gives E2064 on XE ... Why? Is it possible to configure XE to behave in 2009? Or should I go a workaround?

unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TTestRecord = record FirstItem : Integer; SecondItem : Integer; end; TForm2 = class(TForm) procedure AssignValues; private FTestRecord :TTestRecord; public property TestRecord : TTestRecord read FTestRecord write FTestRecord; end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.AssignValues; begin with TestRecord do begin FirstItem := 14; // this gives error in XE but not in 2009 SecondItem := 15; end; end; end. 
+4
source share
2 answers

The D2010 compiler is more stringent than previous versions. In previous versions, the compiler did not complain, but often the results were not what you would expect, since they acted on a temporary var, so your changes would disappear until the end of the method.

The answers to the question you are referring to give an explanation even better and provide solutions (or workarounds) from which you can choose.

+12
source

OK, OK, sorry, I shouldn't have done non-technical content ...

Now we can change the code as follows, and it works fine:

 type PTestRecord = ^TTestRecord; TTestRecord = record FirstItem: Integer; SecondItem: Integer; end; TForm2 = class(TForm) private { Private declarations } FTestRecord: TTestRecord; procedure AssignValues; public { Public declarations } property TestRecord: TTestRecord read FTestRecord write FTestRecord; end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.AssignValues; begin with PTestRecord(@TestRecord)^ do begin FirstItem := 14; // it works fine. SecondItem := 15; end; end; 
-1
source

Source: https://habr.com/ru/post/1345847/


All Articles