我在 Delphi 2010 上开始项目,然后迁移到 XE,现在我尝试迁移到 XE2。在 XE2(更新 4 修补程序 1)中编译后,单元测试开始以 AV 失败。经过一些调试,很明显以下代码没有正确编译:
program ForwardDeclaration;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
TEntityBase = class(TObject)
protected
FModel: Integer;
public
constructor Create(const AModel: Integer);
end;
TEntity<TKey> = class(TEntityBase)
end;
TMyEntity2 = class;
TMyEntity1 = class(TEntity<Integer>)
FData: Integer;
end;
TMyEntity2 = class(TMyEntity1)
end;
constructor TEntityBase.Create(const AModel: Integer);
begin
inherited Create;
FModel := AModel;
end;
var
MyEntity: TMyEntity1;
begin
try
Writeln(TEntityBase.ClassName, ': ', TEntityBase.InstanceSize, ' bytes');
Writeln(TMyEntity1.ClassName, ': ', TMyEntity1.InstanceSize, ' bytes');
MyEntity := TMyEntity1.Create(100);
Assert(MyEntity.FData = 0);
except
on E: Exception do Writeln(E.ClassName, ': ', E.Message);
end;
end.
程序输出:
TEntityBase: 12 bytes
TMyEntity1: 12 bytes <-- Must be 16 bytes!
EAssertionFailed: Assertion failure (ForwardDeclaration.dpr, line 41)
是否可以通过调整编译器选项来解决问题?
这个问题是否在其他人身上重复?
PS QC107110