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

Anthony Walter sysrpl at gmail.com
Tue Nov 10 23:29:58 CET 2009

Sorry, Create is an identifier.

constructor TSampleForm.Create(AOwner: TComponent);
  Create: Integer;
  Create := Tag;
  Caption := IntToStr(Create);

Aside from that, if you read you will see I used two identifiers ...
one called "Create" and another called ... get this "CreateFromLine".
See that? It's a different identifier (it's not the same).

Test it out yourself.

if 'Create' = 'CreateFromLine' then ; // always evaluates to false

As such, the compiler shouldn't issue a warning about constructors
must be public.

protected constructor CreateFromData(var Data); // there should not be
a warning saying CreateFromData must be public

It should however issue a waring when you try to alter the visbility
of a method:

private procedure FreeInstance; override; // warning or error here is expected

On Tue, Nov 10, 2009 at 4:35 PM, Paul Nicholls <paulfnicholls at gmail.com> wrote:
> ----- Original Message ----- From: "Anthony Walter" <sysrpl at gmail.com>
> To: <graemeg at opensoft.homeip.net>; "FPC-Pascal users discussions"
> <fpc-pascal at lists.freepascal.org>
> Sent: Wednesday, November 11, 2009 1:07 AM
> Subject: Re: [fpc-pascal] Compiler Warning: Constructor should be public
>> Your argument is flawed. Visibility rules apply to identifiers, not
>> keywords.
>> Create // identifier
>> CreateFromLine // different identifier
>> No visibility is being changed by introducing a *new* identifier
>> raise EAssertError.Create(Msg); // still visible
>> raise EAssertError.CreateFromLine(Msg, FileName, LineNumber); // not
>> visible
> <SNIP>
> Hi Anthony,
>   Sorry, but you are incorrect; "Create" is a method, not an identifier, and
> like all methods, it is affected by visibility rules (public, private,
> protected).
> cheers,
> Paul
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list