[fpc-pascal] Compatibility of very similar generic types

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Thu Aug 18 15:09:25 CEST 2016


On Thu, Aug 18, 2016 at 2:44 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> generic procedure WriteVector_To_DM<T>(ADest: TDataManager; ASelf:
> specialize TVector<T>);
> generic procedure ReadVector_From_DM<T>(AFrom: TDataManager; var ASelf:
> specialize TVector<T>);
>
> and use them like this:
>
> specialize WriteVector_To_DM<TSubClass1>(...);

Aha, great, didn't know we had something in this direction. But
correct me if I am wrong, but this wouldn't work in my case, because
my function writes the class to a stream in the end of it, so it needs
to know which type T is. If the type is TSomeClass or a descendent,
then it will write each field of the class to the stream.

But in a generic class/function there is no way to ask if T is an int,
or is an TSomeClass, or am I missing some way of writing code that is
different for various possible types?

thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list