[Lazarus] Error: Generics without specialization cannot be used as a type for a variable
Peter Williams
pewilliams2010 at live.com
Mon May 9 08:32:04 CEST 2011
Hi Sven & all,
> Date: Fri, 6 May 2011 22:06:55 +0200
> From: pascaldragon at googlemail.com
> To: lazarus at lists.lazarus.freepascal.org
> Subject: Re: [Lazarus] Error: Generics without specialization cannot be used as a type for a variable
>
> On 06.05.2011 17:58, Peter Williams wrote:
> > Hi,
> >
> > Options changed, recompiling clean with -B
> > Hint: Start of reading config file /etc/fpc.cfg
> > Hint: End of reading config file /etc/fpc.cfg
> > Free Pascal Compiler version 2.4.2-0 [2010/11/11] for i386
> > Copyright (c) 1993-2010 by Florian Klaempfl
> > Target OS: Linux for i386
> > Compiling island_maker.lpr
> > Compiling unit1.pas
> > unit1.pas(144,19) Error: Generics without specialization cannot be used
> > as a type for a variable
> > unit1.pas(152,1) Fatal: There were 1 errors compiling module, stopping
> >
> > http://62.166.198.202/bug_view_advanced_page.php?bug_id=18101
> >
> > (0043710)
> > Florian Klämpfl (administrator)
> > 2010-11-29 10:47
> >
> > Please use always the latest release compiler (2.4.2) as starting
> > compiler to build a new fpc.
> >
> >
> > NB - I am using FPC 2.4.2.
> >
> > type
> > Terrain_type = (Land, Sea);
> >
> > exit_type = array[ directions ] of integer;
> >
> > description_type = array[1..2] of string;
> >
> > Tmap_detail = Object
> > FTerrain : Terrain_type;
> > FTerrain_char : char;
> > Fdescription : description_type;
> > Fx, Fy, Flocation_number : integer;
> > Fexits : exit_type;
> > end;
> >
> > // The Island class definition
> > Generic TIsland<T> = class
> > Items : array of Tmap_detail;
> > public
> > constructor Create(AList: TList);: [Lazarus] dtm_maker project compile
> > errors with TList code.
> > procedure Add( Value : Tmap_detail );
> > end;
> > var
> > Form1: TForm1;
> > Island : TIsland; // line 144
> >
> > Unit1.pas >>> http://pastebin.com/wuEft4Kb
>
> Why do you declare TIsland as a generic if you don't use the type "T"
> anywhere?
>
> Nevertheless, you need to declare a specialized type of a generic, so
> you're able to use it.
>
> Example:
>
> type
> TIntegerIsland = specialize TIsland<Integer>;
>
> var
> Island: TIntegerIsland;
> (...)
Okay, except that Island is not meant to be an integer. See here:
line 88Tmap_detail = Object FTerrain : Terrain_type; FTerrain_char : char; Fdescription : description_type; Fx, Fy, Flocation_number : integer; Fexits : exit_type; end; // The Island class definition Generic TIsland<T> = class Items : array of Tmap_detail; public constructor Create(AList: TList); procedure Add( Value : Tmap_detail ); end;
So, as you can see, I am trying to define a Generic (or possibly a Specialize) of type: an array of Tmap_detail. How do I correctly define this???
The reason why I am choosing a Generic or Specialize is so that I have accept to the "Sort" procedure of TList. I am not sure if I am doing this correctly.
Best Regards,Peter
>
> Regards,
> Sven
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110509/ae3a364b/attachment-0003.html>
More information about the Lazarus
mailing list