定义混合静态和动态元素的const多维数组的delphi

时间:2019-08-29 11:10:00

标签: delphi pascal

在创建多维数组时是否可以混合使用静态数组和动态数组,然后使用该数组定义该类型的const。 编译器似乎对以下内容没有问题,因此我认为将这样的动态和静态数组混合使用是合法的...

TSoftKeyBase = (skEmptyCommandLine, skChannelsSelected);
TSoftKeySet = array of array of String;
TSoftKeys = array[TSoftKeyBase] of TSoftKeySet;

当我尝试为此数组定义一个const时,我在内部元素列表上不断得到“需要序数类型”。我会超越语言的范围吗?

const
  SOFT_KEYS: TSoftKeys =
      [
        [
          ['Select Previous', 'Page',         'Close',        'SC',             'Park',             'MORE >'],
          ['Output',          'FX',           'Macro',        'Select Active',  'Select Changed',   'MORE >'],
          ['Cue List',        'Re Cue List',  'Load',         'Inclusive Mode', 'Active Sel Mode',  'MORE >'],
          ['If',              'View',         'Scroll To',    '',               '',                 'MORE >']
        ],
        [
          ['Select Previous', 'Last',         'Next',         'Clear Selection','Park',             'MORE >'],
          ['Down %',          'Up %',         'Home',         'Select Active',  'Select Changed',   'MORE >'],
          ['Virtual DSC',     'HiLight',      'LoLight',      'Fan',            'Offset',           'MORE >'],
          ['',                '',             '',             '',               '@ ATTs',           'MORE >']
        ]
      ];

1 个答案:

答案 0 :(得分:2)

您需要在最外层(array[TSoftKeyBase])上使用普通括号,因为它是静态数组(而不是动态数组或集合)。

const
  SOFT_KEYS: TSoftKeys =
      (
        [
          ['Select Previous', 'Page',         'Close',        'SC',             'Park',             'MORE >'],
          ['Output',          'FX',           'Macro',        'Select Active',  'Select Changed',   'MORE >'],
          ['Cue List',        'Re Cue List',  'Load',         'Inclusive Mode', 'Active Sel Mode',  'MORE >'],
          ['If',              'View',         'Scroll To',    '',               '',                 'MORE >']
        ],
        [
          ['Select Previous', 'Last',         'Next',         'Clear Selection','Park',             'MORE >'],
          ['Down %',          'Up %',         'Home',         'Select Active',  'Select Changed',   'MORE >'],
          ['Virtual DSC',     'HiLight',      'LoLight',      'Fan',            'Offset',           'MORE >'],
          ['',                '',             '',             '',               '@ ATTs',           'MORE >']
        ]
      );

简单示例:

type
  TTest = array[0..2] of Integer; // static array

const
  Data: TTest = (10, 20, 30);

type
  TTest = array of Integer; // dynamic array

const
  Data: TTest = [10, 20, 30];

type
  TTest = set of Byte; // set

const
  Data: TTest = [10, 20, 30];