Or make proc() a member of TGenClass?
that how it was in my code for FPC3.0. In FPC 3.2 it is not allowed.
project1.lpr(31,27) Error: Generics without specialization cannot be used as a type for a variable
Any way to force the typecast?
construct a nice class hierarchy or work with interfaces if you need something specific.
The history of this generic is following.
There was type TFastList, that was kind of TFPList. It was not generic.
In program it was used to store pointers of all kinds of objects. It can be sorted and fast searchable. Internally it converts object pointer to PtrUInt to sort.
I've made it generic and specialized it for the classes to organize its usage and improve safety.
However in some places there are procedures that previously accepted TFastList parameter and can work with related classes like TClassA and TClassB=class(TClassA).
A TGenClass<TClassA> can contain other descendants of TClassA which could lead to problems with accessing them as a TGenClass<TClassB>. And even the other way round (as you have it) can lead to problems, for example if non-virtual methods are called inside the generic.
Here I do not understand. If in other places of program I can define a variable V:TClassA and then assign TClassB instance to it and use it, why a generic specialized to TClassA cannot do it? The var V is also sort of "specialized" to TClassA, but it can do it.
In reality my class TFastList is type agnostic. It is just sorted pointers list. And it does not even call any methods of the objects.
I know the example is not like this. But anyway.
What would be a workaround?