我在Delphi XE SP 1中试过这个,请参阅代码中的注释。 从来没有尝试过更新的版本,现在还没有安装它们,有人熟悉这个bug吗?在他们的质量控制中找不到任何东西......
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.
谢谢TK
答案 0 :(得分:1)
只需复制以上评论中的答案: qc.embarcadero.com/wc/qcmain.aspx?d=101308 在Delphi XE4中解决了错误。