[fpc-pascal] How to add new methods in a existent generic type?

Sven Barth pascaldragon at googlemail.com
Wed Feb 26 17:28:50 CET 2014


Am 26.02.2014 16:11, schrieb silvioprog:
> Hello,
>
> I'm trying to add new features in a third generic type. Please see 
> this simulation below:
>
>   { TThirdGeneric }
>
>   generic TThirdGeneric<T> = class
>   private
>     FFoo: T;
>   public
>     procedure Post;
>     property Foo: T read FFoo;
>   end;
>
>   { TMyGeneric }
>
>   generic TMyGeneric<T> = class(TThirdGeneric)
This must be "class(specialize TThirdGeneric<T>)" (the "T" is the same 
type parameter as specified for the "TMyGeneric" declaration, so if it 
would be "TMyGeneric<MyType>" it would need to be "class(specialize 
TThirdGeneric<MyType>)")
>   public
>     procedure ConfigureFoo;
>   end;
>
>   { TMyClass }
>
>   TMyClass = class(TMyGeneric)
A class parent must always be a specialization as generics are no valid 
types per se. So here the correct declaration would again be 
"class(specialize TMyGeneric<WhateverTypeYouNeed>)".
>   public
>     procedure Post;
>   end;
[snip]
> Just trying to understand the generics concept correctly. :S

Regards,
Sven



More information about the fpc-pascal mailing list