Talk:Generics proposals

From Free Pascal wiki
Revision as of 16:43, 29 October 2010 by Chronos (talk | contribs) (Talk:Generics moved to Talk:Generics proposals: Page Generics should contain information about existed implementation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

I wouldn't allow this:

 var
   intlist: GList<Integer>;
 begin
   intlist := GList<Integer>.Create;
 end;

only

 type 
   tintlist: GList<Integer>;
 var
   intlist: tintlist; 
 begin
   intlist := tintlist.Create;
 end;

This makes parsing easier and is in the spirit of pascal.

--FPK 09:52, 3 Mar 2005 (CET)

Solution in Borland's QC

http://qc.borland.com/wc/qcmain.aspx?d=11168


type

 TList<_t> = class
   Data: array of _t;
   procedure Add(Item: _t);
   function Extract(Item: _t): _t;
 end;

type

 TComponentList = TList<TComponent>;
 TIntegerList = TList<Integer>;
 ...

var

 x: TComponentList;
 y: TIntegerList;

begin

 x := TComponentList.Create;
 x.Add(Form1);
 ...
 y := TIntegerList.Create;
 y.Add(1234);
 ...

end.