[fpc-pascal] Usage of Generics in FPC

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Feb 12 11:26:11 CET 2009


Hi,

I've been playing around with Generics for a few hours - simply to see
what all the fuss is about.
I was given the following Delphi link to help explain generics.
  http://sjrd.developpez.com/delphi/tutoriel/generics/

I noticed very early on that FPC has a very different sytax to Delphi.
I guess that's because FPC implemented generics first? The catch-22
case. Do we innovate and be the first (of our competitors) to support
generics, or do we wait and simply follow the crowd. Obviously there
are pros and cons for both cases. Are there plans to change the syntax
to match Delphi?  I don't want to implement many things now, simply to
have to change them in the future when the syntax gets updated.

Anyway, I found the "fgl.pp" unit which contains a generic list:
TFPGList class. Does FPC include any other classes for use with
generics?


Why can't I do the following:

procedure WriteSquares(AMax: Integer);
var
  List: specialize TFPGList<integer>;
begin
  List := TFPGList<integer>.Create;


...instead I have to ALWAYS declare a type first....


type
  TIntList = specialize TFPGList<Integer>;

procedure WriteSquares(AMax: Integer);
var
  List: TIntList;
begin
  List := TIntList.Create;



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list