class(specialize TFPGObjectList<T>) -> Incomplete creation.

Summary

When a specialized TFPGObjectList has a constructor Create; of its own, calling inherited fails to to go thru TFPGObjectList.Create thus failing setting ItemSize. That leads to crash on first add to the list.

System Information

  • Operating system: Windows (Probaby all)
  • Processor architecture: x86-64 (Probaby all)
  • Compiler version: 3.2, 3.3, trunk
  • Device: Laptop

Steps to reproduce

Load Example Project.

Example Project

program Project1;

{$mode ObjFPC}{$H+}

uses
  Classes,
  SysUtils,
  fgl;

const
  cSymInvalid = low(integer);

type

  { TSymbolItem }

  TSymbolItem = class(TObject)
  private
    fSym: integer;
  public
    procedure Clear;
    property Sym: integer read fSym write fSym;
  end; {TSymbolItem}

  { TSymbolBufferList - circular buffer list }

  TSymbolBufferList = class(specialize TFPGObjectList<TSymbolItem>)
  private
    const cCap = 16; { The circular list of cached items }
  private
  protected
  public
    constructor Create;
  end;

  { TSymbolItem }

  procedure TSymbolItem.Clear;
  begin
    fSym := cSymInvalid;
  end; { Clear }

  { TSymbolBufferList }

  constructor TSymbolBufferList.Create;
  var
    i: integer;
    lNewSymPos: TSymbolItem;
  begin
    inherited;
    for i := 0 to cCap - 1 do begin
      lNewSymPos := TSymbolItem.Create;
      lNewSymPos.Clear;
      Add(lNewSymPos); // <<<<<<<<------------- ERROR HERE
    end;
  end;

var
  vSymbolBufferList: TSymbolBufferList;
begin
  vSymbolBufferList := TSymbolBufferList.Create;
  vSymbolBufferList.Free;
  ReadLn;
end.

What is the current bug behavior?

Project project1 raised exception class 'External: ACCESS VIOLATION' with message: Access violation writing to address $0000000000000000.

In file 'fgl.pp' at line 1067

What is the expected (correct) behavior?

No error.

Possible fixes

[Edit : sadly it breaks some constructs] >fgl_create.diff

Edited by Bruno K