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

Joao Morais l at joaomorais.com.br
Fri Feb 28 11:53:37 CET 2014


Em 27/02/14 19:56, luiz americo pereira camara escreveu:
>
>
>
> 2014-02-27 18:43 GMT-03:00 Joao Morais <l at joaomorais.com.br 
> <mailto:l at joaomorais.com.br>>:
>
>     Correct. The feature I was talking about is something like:
>
>     generic TMyGeneric<T: TMyType>
>
>     And TMyType is a class. In this case the compiler knows I am
>     talking about a generic for a class type and a "generic as Java"
>     becomes possible.
>
>
>
> Seems that you are looking to class type constraints:
>
> http://docwiki.embarcadero.com/RADStudio/XE4/en/Constraints_in_Generics
> http://blogs.teamb.com/craigstuntz/2008/08/29/37832
>
> Not sure if will allows to do what you are looking for

Kind of. I usually want some type safety in a generic implementation. A 
couple of weeks ago I needed a generic type as an abstract class 
(changed the approach, don't remember details). Most of the time 
reintroduce some methods casting the inherited one solves the problem.

Thanks for the links! I didn't know the actual Delphi syntax =)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140228/4550a2d0/attachment.html>


More information about the fpc-pascal mailing list