I tried this in Delphi XE SP 1, see comment in code. Never tried in newer revisions, have not installed them now, is somebody familiar with this bug? Didn't find anything in their QC either...
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.
Thank you TK
Just copying answer from the comments above: qc.embarcadero.com/wc/qcmain.aspx?d=101308 Bug resolved in Delphi XE4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With