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

后端 未结 4 1692
天涯浪人
天涯浪人 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:33

    AFAIK, you can't do that.
    But if the goal is to ensure you declare your actual constant string only once, I suggest you declare the individual strings and then group them in arrays:

    const
      MyConst1 = 'Hi';
      MyConst2 = 'Foo';
      MyConst3 = 'Bar';
      MyFirstConstArray: array[0..1] of string = (MyConst1, MyConst2);
      MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string = 
        (MyConst1, MyConst2, MyConst3);
    

    BTW, your syntax is incorrect, you have to precise the type of the array elements.

提交回复
热议问题