[fpc-pascal] Override constructor in class helper?

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Nov 27 19:53:46 CET 2025



On 11/27/25 11:24, Thomas Kurz via fpc-pascal wrote:
> Hello,
> 
> what I'm trying to do is something like this:
> 
> TStringStreamHelper = class helper for TStringStream
>    constructor Create;
>    constructor Create (const AString: AnsiString);
> end;
> 
> constructor TStringStreamHelper.create;
> begin
>    inherited Create ('', TEncoding.UTF8);
> end;
> 
> constructor TStringStreamHelper.create (const AString: AnsiString);
> begin
>    inherited Create (AString, TEncoding.UTF8);
> end;
> 
> Both ChatGPT and Gemini agree that this won't work because FPC resolves Create in this order:
> 1. Look at the real class (TStringList) for a matching constructor.
> 2. Only if no such method exists, check helpers in scope for a matching name.

I hope you did not pay them for that answer.


> However, if I try, the helper constructor *is* invoked.
> 
> Because I'm on FPC 3.3.1 trunk, I wonder whether this is indended behavior and I can rely on it in the future, or whether this is a bug and will break in the final 3.4.0 release.

Intended.

Mattias



More information about the fpc-pascal mailing list