Difference between revisions of "Talk:Generics proposals"

From Free Pascal wiki
Jump to navigationJump to search
 
m (Talk:Generics moved to Talk:Generics proposals: Page Generics should contain information about existed implementation.)
(One intermediate revision by the same user not shown)
Line 19: Line 19:
  
 
--[[User:FPK|FPK]] 09:52, 3 Mar 2005 (CET)
 
--[[User:FPK|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.

Revision as of 16:43, 29 October 2010

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.