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

silvioprog silvioprog at gmail.com
Tue Feb 25 00:27:02 CET 2014


Hello,

I have this structure:

  generic TMyGeneric<T> = class
  end;

  TMyGenericClass = class of TMyGeneric;

  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?

Thank you!

-- 
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/20140224/747f9d86/attachment.html>


More information about the fpc-pascal mailing list