[fpc-devel] interfaces / inheritance / again -
Michael Van Canneyt
michael at freepascal.org
Mon Feb 2 20:48:59 CET 2026
On Mon, 2 Feb 2026, Martin Frb via fpc-devel wrote:
> Not yet tested, but only matters if it is not going to be discontinued
> (in case it actually works)
>
> I want a
> generic Foo <_A: SomeIntf; _B: TBar>
>
> such as that I can give an inherhited interface.
>
> The interface has
> GetBar => which return TBar => or subclass....
> Hence for the generic I have a param to specify the class.
>
>
> But, I cans do
> IFoo = interface
> proceduer GetBar: TBar;
>
> ISubFoo = interface(Foo)
> proceduer GetBar: TSubBar;
Are you deliberately trying to shoot yourself in the foot here ?
(better your foot than my foot obviously...)
>
> However, (tests pending) if the below works, would it be working by
> indent? And therefore not removed by some bug fix in future?
>
> IFoo = interface
> proceduer GetBar: TBar;
> property Bar: TBar;
I assume this should be:
property Bar: TBar read GetBar;
>
> ISubFoo = interface(Foo)
> proceduer GetSubBar: TSubBar;
> property Bar: TSubBar;
Similarly, I assume you mean
property Bar: TSubBar read GetSubBar;
property overrides exist, but they must keep the same type, they can only
change the specifiers. So I don't think this will compile. If it does, it
is probably by accident.
> The property is just syntactic sugar isn't it?
> But the generic would see it according to the actual type of the gen param.
I don't know, but to me it looks like a definite way to confuse yourself and others.
I would define this as
ISubFoo = interface(Foo)
procedure GetSubBar: TSubBar;
property SubBar: TSubBar;
end;
Michael.
More information about the fpc-devel
mailing list