[fpc-pascal] How to use generics and meta class?

silvioprog silvioprog at gmail.com
Wed Feb 26 16:22:57 CET 2014


Oops...

2014-02-26 12:16 GMT-03:00 silvioprog <silvioprog at gmail.com>:
[...]

> I tried that but:
>
> "Identifier not found "TMyGenericClass"".
>

Full test below:

  generic TMyGeneric<T> = class
  public type
    TMyGenericClass = class of TMyGeneric;
  end;

  TMyService = class
  public
    class procedure RegisterItem(aItemClass: TMyGeneric.TMyGenericClass);
  end;

  TMyClass = class(specialize TMyGeneric<TObject>)
  end;

..

begin
  TMyService.RegisterItem(TMyClass);
end;

Error: Incompatible type for arg no. 1: Got "Class Of TMyClass", expected
"TMyGeneric.TMyGenericClass"

The only alternative is use "class procedure RegisterItem(aItemClass:
TClass);" instead of "class procedure RegisterItem(aItemClass:
*MyGenericType*);"?

-- 
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/d7f8e5ad/attachment.html>


More information about the fpc-pascal mailing list