[fpc-pascal] Override constructor in class helper?
Thomas Kurz
fpc.2021 at t-net.ruhr
Thu Nov 27 11:24:48 CET 2025
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.
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.
It'd be nice if someone could clarify this.
Thank you
Thomas
More information about the fpc-pascal
mailing list