[fpc-pascal] How to use generics and meta class?
silvioprog
silvioprog at gmail.com
Wed Feb 26 04:40:07 CET 2014
2014-02-25 5:14 GMT-03:00 Sven Barth <pascaldragon at googlemail.com>:
> Am 25.02.2014 00:27, schrieb silvioprog:
>
>> Hello,
>>
>> I have this structure:
>>
>> generic TMyGeneric<T> = class
>> end;
>>
>> TMyGenericClass = class of TMyGeneric;
>>
> That must not compile. This is a bug.
Can you issue it for me friend? I would be thankful. (y)
TMyType = class
>> end;
>>
>> TMyClass1 = specialize TMyGeneric<TMyType>;
>>
>> TMyClass2 = class(specialize TMyGeneric<TMyType>)
>> end;
>>
>> ...
>>
>> procedure RegisterItem(AItemClass: TMyGenericClass);
>> begin
>> end;
>>
>> OK, but when I try:
>>
>> RegisterItem(TMyClass1);
>>
>> Return:
>>
>> Incompatible type for arg no. 1: Got "Class Of TMyGeneric$TMyType",
>> expected "TMyGenericClass".
>>
>> Or:
>>
>> RegisterItem(TMyClass2);
>>
>> Return:
>>
>> Incompatible type for arg no. 1: Got "Class Of TMyClass2", expected
>> "TMyGenericClass"
>>
>> So, which syntax to use generic and meta class?
>>
> You can't. A generic is by definition not a fully existant type. You can
> only work with specializations.
> E.g. TFPGList<> circumvents this by having the main implementation of the
> list inside a non generic TFPSList type which TFPGList<> derives from.
>
> Regards,
> Sven
Thank for this nice information, I didn't know that.
--
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140226/4bebe848/attachment.html>
More information about the fpc-pascal
mailing list