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

Pew (piffle.the.cat) piffle.the.cat at iinet.net.au
Sat Jan 8 19:43:46 CET 2011


Hi Howard,

On 01/08/2011 11:09 PM, Howard Page-Clark wrote:
> On 08/1/11 10:13, Pew (piffle.the.cat) wrote:
>> Hi Lazarus list,
> ...
>> 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
Thank you. My pascal is a bit rusty and I have an excellent text book, 
however, I need to buy some new reading glasses. I will do that on 
Monday. :-)
> You want the following:
>
> type
>   green_types = ( Fragments, Babies, Adults, Eggs, 
> Group_of_Green_things );
>
>   fragments_to_eggs_subrange = Fragments..Eggs;
>
> const
>   GreenTypeStrings : array[green_types] of string =
>     (' stunned the Fragment', ' stunned the Baby', ' stunned the Adult',
>     ' stunned the Egg', ' stunned the Group of Green Things');

// not compiled yet

const

   article : array[1..2] of AnsiString = 'a', 'an';
   definitive_article = 'The ';

   AnsiString_noun_of_green_message
     : array[green_types] of AnsiString =
     (' Fragment', ' Baby', ' Adult',
     ' Egg', ' Group of Green Things');

   AnsiString_constitution_is = ' constitution is: ';

   AnsiString_He_rolled_a = 'He rolled a ';

   AnsiString_stunned_the_green_message = ' stunned ';

   AnsiString_killed_the_green_message = ' killed';

   AnsiString_There_is_no_longer = 'There is no longer';

   AnsiString_here_to_attack = ' here to attack.';

   AnsiString_survived_the_attack = ' survived the attack.');

My next step is to change the const definition to variables so that I 
can define:

type
   languages = ( English, Italian, German, Spanish, Esperanto, 
Simplified_Chinese, Japanese );

// I probably need to define the font name for each language also
// does anyone know the standard linux fonts for these languages???

   article_language_array = array[languages] of AnsiString;
   definitive_article_array = array[languages] of AnsiString;

   AnsiString_noun_of_green_message_2D_array =
     array[languages,green_types] of AnsiString;

// etc etc etc

var
   article_language : article_language_array;
   definitive_article : definitive_article_array;
   AnsiString_There_is_no_longer : array[ languages ] of AnsiString;
   AnsiString_noun_of_green_things :array[ languages, green_jj ]of 
AnsiString;
   AnsiString_here_to_attack :array[ languages ]of AnsiString;
   language : languages;
begin

{

Ask user for language preference
Open ini file and read file containing Ansi constants
close ini file
read and assign AnsiStrings from text file to variables
close text file

}

   info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+
      AnsiString_here_to_attack[ language ] );

end;

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
     article[language, 2]+' '+AnsiString_noun_of_green_message[Egg]then
       green_jj := Eggs
   else
     if attacking_what =
        // a Baby
article[language,1]+' '+AnsiString_noun_of_green_message[Babies]then
       green_jj := Babies
     else
       if attacking_what =
         // a Fragment
         article[language,1]+' 
'+AnsiString_noun_of_green_message[Fragments]then
         green_jj := Fragments
       else
         if attacking_what =
            // an Adult
article[language,2]+' '+AnsiString_noun_of_green_message[Adults]then
           green_jj := Adults
         else { a group of Green Things }
           green_jj := Group_of_Green_things;
   end;

   info_form.SynMemo1.lines.add( definitive_article +

     //green_types = ( Fragments, Babies, Adults, Eggs, 
Group_of_Green_things );
// e.g. The Egg's constitution is xxx
     // etc

     AnsiString_noun_of_green_message[ language, green_jj ] + ''' +
     AnsiString_constitution_is[ language ] +
     inttostr( green_stats[ eggs ].constitution ) );

   info_form.SynMemo1.lines.add( AnsiString_He_rolled_ a + inttostr( 
roll ) );

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

   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 +
              AnsiString_stunned_the_green_message[ language ]+
              AnsiString_noun_of_green_things[ language, green_jj ]);
          end
          else
           info_form.SynMemo1.lines.add( name +
AnsiString_killed_the_green_message[ language ]+
               AnsiString_noun_of_green_things[ language, green_jj ]);
          end
     else
info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+
         AnsiString_here_to_attack[ language ] );
     end
   else
info_form.SynMemo1.lines.add(
AnsiString_definitive_article[ language ] +
AnsiString_noun_of_green_things[ green_jj ]+
         AnsiString_survived_the_attack[ language ] );
   end;
[...]

There are actually different arrays of strings for different states of 
action with the Green Things.
> HTH
>
> Howard
>

Peter :-)))


pew

> -- 
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus





More information about the Lazarus mailing list