Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

Is static strings prosible?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Torsten Bonde Christiansen

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;

Reply by email