将项目从2009升级到XE时出现Delphi"E2064左侧无法分配"错误

LaB*_*cca 4 delphi compiler-errors delphi-2009 delphi-xe

我读到了这个问题,其中讨论了同样的问题,无论如何我能够在Delphi 2009中做到这一点,这是不可能的,因为我升级到XE.

我在这里粘贴一个简单的虚拟示例:这在2009年编译并在XE上提供E2064 ...为什么?是否有可能将XE设置为像2009年一样?或者我应该去寻找解决方法?

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.
Run Code Online (Sandbox Code Playgroud)

Mar*_*ema 12

D2010编译器比以前的版本更严格.在以前的版本中,编译器没有抱怨,但通常结果不会如您所期望的那样,因为它在临时var上运行,因此您的更改将在方法结束时消失.

您链接的问题的答案提供了更好的解释,并提供了可供选择的解决方案(或解决方法).

  • 换句话说,感谢XE编译器不再让你自己开枪.+1. (9认同)