Delphi:相同内存位置的两个字段 - 编译器错误?

tk_*_*tk_ 7 delphi generics

我在Delphi XE SP 1中尝试过这个,请参阅代码中的注释.从来没有尝试过更新的版本,现在还没有安装它们,有人熟悉这个bug吗?他们的QC中没有找到任何东西......

unit Testing;

interface

uses
  Generics.Collections;

type
  TBaseObjectList<T: class> = class(TObjectList<T>)
  private
    FUpdateLock: Integer;
  public
    constructor Create; virtual;
    procedure LockUpdate;
    procedure UnlockUpdate;
    function UpdateUnlocked: Boolean;
    property UpdateLock: Integer read FUpdateLock;
  end;

  TAdvObject = class(TObject)
  end;

  TAdvObjectList = class(TBaseObjectList<TAdvObject>)
  private
    FHelper: Integer;
  public
    constructor Create;
    property Helper: Integer read Fhelper;
  end;

implementation

{ TBaseObjectList<T> }

constructor TBaseObjectList<T>.Create;
begin
  inherited Create;
  FUpdateLock := 0;
end;

procedure TBaseObjectList<T>.LockUpdate;
begin
  Inc(FUpdateLock);
end;

procedure TBaseObjectList<T>.UnlockUpdate;
begin
  if FUpdateLock > 0 then
    Dec(FUpdateLock);
end;

function TBaseObjectList<T>.UpdateUnlocked: Boolean;
begin
  Result := FUpdateLock = 0;
end;

{ TAdvObjectList }

constructor TAdvObjectList.Create;
begin
  LockUpdate;
  try
    // this increments FUpdateLock as well because FHelper and FUpdateLock are mapped to same memory location, it can be seen in debugger watches, it seems to me to be a bug
    Inc(FHelper);
  finally
    UnlockUpdate;
  end;
end;

begin
  TAdvObjectList.Create;
end.
Run Code Online (Sandbox Code Playgroud)

谢谢TK

tk_*_*tk_ 1

只需复制上面评论中的答案:qc.embarcadero.com/wc/qcmain.aspx?d=101308 Delphi XE4 中已解决的错误。