我在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); …Run Code Online (Sandbox Code Playgroud)