[Lazarus] Compile time errors. Error: Duplicate identifier "Fragments" line 21 and AnsiStrings question.

Pew (piffle.the.cat) piffle.the.cat at iinet.net.au
Sat Jan 8 11:13:55 CET 2011


Hi Lazarus list,

I am updating some working code by rewriting some of the constant 
declarations. It is for a game called Awful Mint Things from Outer Space 
which is a free clone of Awful Green Things from Outer Space, and will 
be released under GNU GPL 3, around January or February.

Note that I am having trouble reading my Pascal text books as I have 
misplaced my reading glasses :-( !!!

I currently have 2 issues:
1) How do I define fragments_to_eggs_subrange which is an enumerated 
portion of green_types.
2) How do I define a constant array of strings // 
string_stunned_the_green_message, etc

The constant array of string is needed for converting messages in my 
Lazarus application for cross language translation e.g. French, Spanish, 
Italian, Esperanto, etc.

I intend to use http://www.langtolang.com for the translations.

I think that I will modify my code to read an inifile then use 
TStringLists or similar and the LoadFromFile method. Will this work?!? I 
believe that I cannot use plain strings as these language use special 
symbols over the characters ?emluts? etc. How are these represented as 
strings or AnsiStrings?

unit test1;

{$mode objfpc}{$H+}

interface

uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;

type
   TForm1 = class(TForm)
   private
     { private declarations }
   public
     { public declarations }
   end;

type
   green_types = ( Fragments, Babies, Adults, Eggs, Group_of_Green_things );

// line 21
   fragments_to_eggs_subrange = (Fragments..Eggs) : green_types;
//                              ^^^^^^^^^
//test1.pas(21,42) Error: Duplicate identifier "Fragments"
//test1.pas(21,42) Hint: Identifier already defined in test1.pas at line 19
//test1.pas(21,42) Fatal: Syntax error, ")" expected but ".." foundunit 
test1.pas

Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling testproject1.lpr
Compiling test1.pas
test1.pas(21,42) Error: Duplicate identifier "Fragments"
test1.pas(21,42) Hint: Identifier already defined in test1.pas at line 19
test1.pas(21,42) Fatal: Syntax error, ")" expected but ".." foundunit 
test1.pas

   babies_to_eggs_subrange = (Babies..Eggs) : green_types;

   green_things_type = record
                         present_count = array[ 
fragments_to_eggs_subrange ] of
                           integer;
                         stunned_count = array[ 
fragments_to_eggs_subrange ] of
                           integer;
                         new_count = array[ babies_to_eggs_subrange ] of
                           integer;
                       end;

var
   green_things : array[ room_subrange   ] of green_things_type;


procedure do_kill_stun( lower, upper : byte;
                         trying_to_stun : boolean;
                         j : integer );

type
   array_of_green_types_strings
     = array[ green_types ] : string;

   string_stunned_the_green_message
    = array_of_green_types_strings;

   string_killed_the_green_message
    = array_of_green_types_strings;

   string_no_longer_here_the_green_message
    = array_of_green_types_strings;

   string_survived_message
    = array_of_green_types_strings;

const
   string_stunned_the_green_message
     [ Fragments ] =
     ' stunned the Fragment';
   string_stunned_the_green_message
     [ Babies    ] =
     ' stunned the Baby';
   string_stunned_the_green_message
     [ Adults    ] =
     ' stunned the Adult';
   string_stunned_the_green_message
     [ Eggs      ] =
     ' stunned the Egg';
   string_stunned_the_green_message
     [ Group_of_Green_Things ] =
     ' stunned the Group of Green Things';

[snip]
var
   green,
   green_jj : green_types;
   k, count : byte;
   temp_green_count : array[ fragments_to_eggs_subrange ] of integer;
begin
   roll := random_in_range( lower, upper );
   if attacking_what = 'an Egg' then
     green_jj := Eggs
   else
     if attacking_what = 'a Baby' then
       green_jj := Babies
     else
       if attacking_what = 'a fragment' then
         green_jj := Fragments
       else
         if attacking_what = 'an Adult' then
           green_jj := Adults
         else { attacking a group }
           green_jj := Group_of_Green_things;
   end;
   info_form.SynMemo1.lines.add( 'The Egg''s constitution is: ' +
     inttostr( green_stats[ eggs ].constitution ) );
   info_form.SynMemo1.lines.add( 'He rolled a ' + inttostr( roll ) );

   temp_green_count[ green_jj ] := crew_data[ j 
].green_data.present_count[ green_jj ];

  case green_jj of
     Fragments..Eggs :
       begin
         if roll >= green_stats[ green_jj ].constitution then
           begin
             if green_things[ attack_room_no ].present_count[ green_jj ] 
 > 0 then
               begin
                 dec( green_things[ attack_room_no ].present_count[ 
green_jj ] );
                 if trying_to_stun then
                   begin
                     inc( green_things[ attack_room_no ].stunned_count[ 
green_jj ] );
                     info_form.SynMemo1.lines.add( name + ' stunned the 
Egg.');
                   end
                 else
                   info_form.SynMemo1.lines.add( name + ' killed the Egg.');
               end
             else
               info_form.SynMemo1.lines.add( 'There is no longer an Egg 
here to attack.');
           end
           else
             info_form.SynMemo1.lines.add( 'The Egg survived the attack.');
       end;
[...]

Regards,
     pew




More information about the Lazarus mailing list