[Lazarus] Error: Generics without specialization cannot be used as a type for a variable
Peter Williams
pewilliams2010 at live.com
Tue May 10 16:30:02 CEST 2011
Hi All,
[snip]> >> > Unit1.pas >>> http://pastebin.com/wuEft4Kb> > Why do you declare TIsland as a generic if you don't use the type "T" > anywhere?
I have (though all of these posts) been trying to follow the instructions for GENERICS on this page:http://wiki.lazarus.freepascal.org/GenericsThis page makes no reference to SPECIALIZE keyword. That is where I got the reference to type "T".Can someone please provide an example of using a TList and an object (as in my code) so that I had access to a custom Tlist with the Sort procedure... which is really my reason for needing this.
> > 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
Best Regards,Peter
> >> Regards,>> Sven>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110511/ee0c3083/attachment-0003.html>
More information about the Lazarus
mailing list