[fpc-pascal] Usage of Generics in FPC

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


On Thu, Feb 12, 2009 at 1:46 PM, Florian Klaempfl
<florian at freepascal.org> wrote:
> You can't do
>
> longintpointer:=^longint(p);
>
> in pascal either but you need
>
> type
> plongint = ^longint;
>
> ...
> longintpointer:=plongint(p);
>
> so it's imo logical that generics must be specialized explicitly before
> they can be used. Same applies e.g. for parameter types too.

Just asked, because the following IS possible in Delphi. Either way,
explicit type (as was shown in my second example) is slightly neater
for me as well.

uses
  SysUtils, Classes, Generics.Collections;

procedure WriteSquares(Max: Integer);
var
  List: TList<Integer>;
  I: Integer;
begin
  List := TList<Integer>.Create;
  try
    for I := 0 to Max do
      List.Add(I*I);
....


Regards,
  - Graeme -


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



More information about the fpc-pascal mailing list