[fpc-devel] Delphi's generic syntax 2

Inoussa OUEDRAOGO inoussa12 at gmail.com
Thu Aug 30 21:57:24 CEST 2007


Hi
This blog ( http://hallvards.blogspot.com/2007/08/highlander2-beta-generics-in-delphi-for.html
)
gives a more complete overview of the up coming Delphi generic's
syntax. Note that the next release of Delphi ( Highlander ) will
consume and produce generics only for .Net; win32 is planned to ship
later.

A quick summery :

1 - No "GENERIC" or "SPECIALIZE" keywords

2 - inline specialization ( var a : TGenericType<Integer>; )

3 - "Default" keyword which when applied to a generic type place-holder
    produce the default value of that type;
    for example
<code>
      var
        a : T;
      begin
        a := Default(T);
      end;

    //could be replaced by the following code but it does not compile(
Should I create a bug report ? ).
      var
        a : T;
      begin
        Fillchar(a,SizeOf(T),#0);
      end;
</code>

4 - Generic method of a non-generic class

5 - Generic interfaces

6 - Generic records; By now fpc supports the following
<code>
     type
      generic TGenRecClass<T> = class
        type
          TRecType = record
            FA : T;
          end;
      end;
      TGenRecClassInt = specialize TGenRecClass<Integer>;
      var
        a : TGenRecClassInt.TRecType;
      //with a inline specialization we could get
      //  b : TGenRecClass<Integer>.TRecType;
</code>


7 - Generic event type

8 - Constraints : allows one to constraint the generic parameters
(type place holder)


-- 
Inoussa O.



More information about the fpc-devel mailing list