[fpc-pascal] How to instantiate a public type in a generic class

luciano de souza luchyanus at gmail.com
Sun May 17 20:46:07 CEST 2015

Hello listers,

Using Freepascal 2.6.4, I have a problem about generics. In short, I
can't specialize a class with a subtype of a type declared with
"public type". Let me try to explain.

In dopf.pas, I have:

generic TdGOpf<T1, T2, T3> = class(TdComponent)
public type
TEntities = specialize TFPGObjectList<T3>

If personmapper is a class specialized from TdGOpf, an instance can be
created as follows:

Personmapper := TPersonMapper.TEntities.create;

Yes, this code is successul. But this code is not:

generic TGAction <t1, t2> = class(specialize TBrookGAction <t1>);
Fentities: t2.TEntities; //Error in type definition

This code failed, so I tried:

generic TGAction <t1, t2> = class(specialize TBrookGAction <t1>);
public type TCEntities = t2.Tentities; //Error in type definition

I got also an error if I try:

generic TGAction <t1, t2, t2.TEntities> = class(specialize TBrookGAction <t1>);

Well, I think the problem is illustrated. The doubt is how can create
an instance of a public type, in my case, t2.Tentities inside my
specialized class?

Best regards,

Luciano de Souza

More information about the fpc-pascal mailing list