[fpc-pascal] Is static strings prosible?

Torsten Bonde Christiansen tc at epidata.dk
Fri Apr 23 13:35:55 CEST 2010


Hi list.

Before I think about creating about report i better ask if it is 
possible to have static string in a class. The following construct 
fails  using fpc 2.4.0 during the decrease of ansistring references.

When cl.free is called, the call to CleanupInstance correctly identifies 
cl.c as a nil pointer, but something is wrong when it tries do 
dereference the reference pointer in fpc_ansistr_decr_ref.

Should I report this is a bug or is static ansistrings not posible?

Kind regards,
Torsten Bonde Christiansen.

========================

  { TBase }

  {$static on}
  TBase = class
  public
    a: string; static;
  public
    constructor Create; virtual;
  end;
  {$static off}

  { TInherited }

  TInherited = class(TBase)
  private
    c: string;
  public
    constructor Create; override;
    destructor Destroy; override;
  end;

var
  cl: TInherited;
begin
  cl := TInherited.Create;
  cl.a := 'asdf';
  cl.Free;
end;

{ TBase }

constructor TBase.Create;
begin

end;

{ TInherited }

constructor TInherited.Create;
begin
  inherited Create;
  c := 'abc';
end;

destructor TInherited.Destroy;
begin
  c := '';
  inherited Destroy;
end;




More information about the fpc-pascal mailing list