<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi Sven & all,<br><br>> Date: Fri, 6 May 2011 22:06:55 +0200<br>> From: pascaldragon@googlemail.com<br>> To: lazarus@lists.lazarus.freepascal.org<br>> Subject: Re: [Lazarus] Error: Generics without specialization cannot be used as a type for a variable<br>> <br>> On 06.05.2011 17:58, Peter Williams wrote:<br>> > Hi,<br>> ><br>> > Options changed, recompiling clean with -B<br>> > Hint: Start of reading config file /etc/fpc.cfg<br>> > Hint: End of reading config file /etc/fpc.cfg<br>> > Free Pascal Compiler version 2.4.2-0 [2010/11/11] for i386<br>> > Copyright (c) 1993-2010 by Florian Klaempfl<br>> > Target OS: Linux for i386<br>> > Compiling island_maker.lpr<br>> > Compiling unit1.pas<br>> > unit1.pas(144,19) Error: Generics without specialization cannot be used<br>> > as a type for a variable<br>> > unit1.pas(152,1) Fatal: There were 1 errors compiling module, stopping<br>> ><br>> > http://62.166.198.202/bug_view_advanced_page.php?bug_id=18101<br>> ><br>> > (0043710)<br>> > Florian Klämpfl (administrator)<br>> > 2010-11-29 10:47<br>> ><br>> >         Please use always the latest release compiler (2.4.2) as starting<br>> > compiler to build a new fpc.<br>> ><br>> ><br>> > NB - I am using FPC 2.4.2.<br>> ><br>> > type<br>> > Terrain_type = (Land, Sea);<br>> ><br>> > exit_type = array[ directions ] of integer;<br>> ><br>> > description_type = array[1..2] of string;<br>> ><br>> > Tmap_detail = Object<br>> > FTerrain : Terrain_type;<br>> > FTerrain_char : char;<br>> > Fdescription : description_type;<br>> > Fx, Fy, Flocation_number : integer;<br>> > Fexits : exit_type;<br>> > end;<br>> ><br>> > // The Island class definition<br>> > Generic TIsland<T> = class<br>> > Items : array of Tmap_detail;<br>> > public<br>> > constructor Create(AList: TList);: [Lazarus] dtm_maker project compile<br>> > errors with TList code.<br>> > procedure Add( Value : Tmap_detail );<br>> > end;<br>> > var<br>> > Form1: TForm1;<br>> > Island : TIsland; // line 144<br>> ><br>> > Unit1.pas >>> http://pastebin.com/wuEft4Kb<br>> <br>> Why do you declare TIsland as a generic if you don't use the type "T" <br>> anywhere?<br>> <br>> Nevertheless, you need to declare a specialized type of a generic, so <br>> you're able to use it.<br>> <br>> Example:<br>> <br>> type<br>>    TIntegerIsland = specialize TIsland<Integer>;<br>> <br>> var<br>>    Island: TIntegerIsland;<br>> (...)<div><br></div><div>Okay, except that Island is not meant to be an integer. See here:</div><div><br></div><div>line 88</div><div><span class="Apple-style-span" style="color: rgb(24, 24, 24); font-family: monospace; font-size: 12px; line-height: 19px; "><ol><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">Tmap_detail <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold; ">Object</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">                 FTerrain <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> Terrain_type;</div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">                 FTerrain_char <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold; ">char</span>;</div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">                 Fdescription <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> description_type;</div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">                 Fx<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> Fy<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> Flocation_number <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold; ">integer</span>;</div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">                 Fexits <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> exit_type;</div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">               <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">end</span>;</div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; "> </div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">  <span class="co1" style="color: rgb(102, 102, 102); font-style: italic; ">// The Island class definition</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">  Generic TIsland<T> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> class</div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">      Items <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold; ">array</span> <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">of</span> Tmap_detail;</div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">    <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">public</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">    <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">constructor</span> Create<span class="br0" style="color: rgb(0, 153, 0); ">(</span>AList<span class="sy0" style="color: rgb(51, 153, 51); ">:</span> TList<span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; "><div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">    <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">procedure</span> Add<span class="br0" style="color: rgb(0, 153, 0); ">(</span> Value <span class="sy0" style="color: rgb(51, 153, 51); ">:</span> Tmap_detail <span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; "><div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">  <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold; ">end</span>;</div></li></ol></span></div><div><br></div><div>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???</div><div><br></div><div>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.</div><div><br></div><div>Best Regards,</div><div>Peter</div><div><br>> <br>> Regards,<br>> Sven<br>> <br>> --<br>> _______________________________________________<br>> Lazarus mailing list<br>> Lazarus@lists.lazarus.freepascal.org<br>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus<br></div>                                       </body>
</html>