//1. 标准方法:var MyArr: array[0..10] of Integer; //定义静态数组--------------------------------------------------------------------------------
//2. 可以使用非0下标:var MyArr: array[9..10] of Integer; //不能提倡,这样不容易与系统函数沟通--------------------------------------------------------------------------------
//3. 根据预定义类型来声明数组:type TMyArr = array[0..10] of Integer; //先定义一个数组类型var MyArr: TMyArr; //再定义静态数组--------------------------------------------------------------------------------
//4. 在非过程区可以直接赋值:var MyArr: array[0..2] of Integer = (11,22,33);--------------------------------------------------------------------------------
//5. 多维数组:var MyArr: array[0..2, 0..2] of Integer;begin //使用 MyArr[1,2] := 100;end;--------------------------------------------------------------------------------
//6. 根据子界定义数组:type TRange = 0..10;var MyArr: array[TRange] of Integer;--------------------------------------------------------------------------------
//7. 根据枚举定义数组:type TEnums = (Enum1,Enum2,Enum3);var MyArr: array[TEnums] of string;begin MyArr[Enum1] := '万一'; ShowMessage(MyArr[Enum1]); //万一end;--------------------------------------------------------------------------------
//8. 根据其他类型定义数组:var MyArr: array[Byte] of Char;begin MyArr[255] := #65; ShowMessage(MyArr[255]); //Aend;
//应尽量不使用内建类型,可以新建类型:type TNewByte = Byte;var MyArr: array[TNewByte] of Char;begin MyArr[255] := #65; ShowMessage(MyArr[255]); //Aend;
//也可以使用类型别名:type TChar = type Char;var MyArr: array[TChar] of Byte;begin MyArr['C'] := 255; ShowMessage(IntToStr(MyArr['C'])); //255end;
//同时定义类型:type MyRec = record s: string; r: Real; b: Byte; end;var Arr1: array[0..100] of MyRec; Arr2: array[0..100] of record s: string; r: Real; b: Byte; end; //可以直接这样定义 Arr3: packed array[0..100] of MyRec; //压缩数组定义, 好像没有区别