Delphi“E2064 左侧无法分配给”将项目从2009升级到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.
I read this question in which the same problem is discussed, anyway i was able to do this in Delphi 2009 and this was not possible as i upgraded to XE.
I paste here a simple dummy example: this compiles on 2009 and gives E2064 on XE... Why? Is it possible to setup XE to behave like 2009? Or should I go for 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
D2010 编译器只是比以前的版本更严格。在以前的版本中,编译器不会抱怨,但结果通常不会像您预期的那样,因为它作用于临时变量,因此您的更改将在方法结束时消失。
您链接到的问题的答案提供了更好的解释,并提供了可供选择的解决方案(或解决方法)。
The D2010 compiler is just more strict than the previous versions were. In the previous versions the compiler didn't complain, but often the results would not be as you would expect as it was acting on a temporary var so your changes would be gone by the end of the method.
The answers on the question to which you linked provide the explanations even better and provide the solutions (or work-arounds) from which to choose.
好吧好吧,对不起,我不应该做出非技术性的内容……
现在,我们可以修改代码如下,就可以正常工作了:
OK, OK, I am sorry, I shouldn't have made non-technical content...
Now, we can modify the code as follows, and it works fine: