[fpc-pascal] Compiler Warning: Constructor should be public

Anthony Walter sysrpl at gmail.com
Tue Nov 10 14:35:52 CET 2009


I've searched the list archives related to the subject of the fpc
warning "Constructor should be public" and am unsure as to the
resolution of this issue, or would perhaps like to revisit it.

In my opinion the warning should be removed, or at least able to be
suppress through a switch. I beginning to make the transition to cross
platform delphi/pascal code. I have many times in the past used
private or protected constructors to signify a class is should be
created outside the unit in which it was defined.

Example:

type
  EAssertError = class(Exception)
  private
    FFileName: string;
    FLineNumber: Integer;
    constructor CreateFromLine(const Msg, FileName: string;
LineNumber: Integer);
  public
    property FileName: string read FFileName;
    property LineNumber: Integer read FLineNumber;
  end;

...

{ EAssertError }

constructor EAssertError.CreateFromLine(const Msg, FileName: string;
LineNumber: Integer);
begin
  inherited Create(Msg);
  FFileName := FileName;
  FLineNumber := LineNumber;
end;

...

procedure AssertErrorProc(const Msg, FileName: string;
  LineNumber: Integer; ErrorAddr: Pointer);
begin
  raise EAssertError.CreateFromLine(Msg, FileName, LineNumber);
end;
...

intialization
  System.AssertErrorProc := @AssertErrorProc;



More information about the fpc-pascal mailing list