Is it possible do Declare a constant array that includes another constant array?

后端 未结 4 1653
天涯浪人
天涯浪人 2021-01-21 15:49

I want to do something like this:

const

  MyFirstConstArray: array[0..1] of string = (\'Hi\', \'Foo\');
  MySecondConstArrayWhichIncludesTheFirstOne: array[0..2         


        
4条回答
  •  不知归路
    2021-01-21 16:30

    Actually, you can but do it using records. i use this technique in a big way for creating definitions for certain behaviours of entities in my software. it's a very powerful technique:

    type
          TPerson=record
            // generally you'd put all kinds of addition stuff here including enums, 
            // sets, etc
            saPets:array[0..2] of string;
          end;
    
    const
      scDog='Dog';
    
      MyPeople:array[0..1] of TPerson=
        ((saPets:(scDog, 'Cat', 'Fish'); ),
         (saPets:('Iguana', 'Tarantula', ''); ));
    
    begin
      ShowMessage(MyPeople[0].saPets[0]);
    
    end;
    

    one thing you can't do with it is refer to resource strings. therefore any translation must be done by the code that retrieves the value. i generally index them with enums--in doing so, i can make the software easier to change because it won't compile if i've left something important out.

提交回复
热议问题