Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-08

Delphi's generic syntax 2

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Inoussa OUEDRAOGO

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.

Reply by email