# Array/zh CN

Deutsch (de) English (en) español (es) suomi (fi) français (fr) Bahasa Indonesia (id) 日本語 (ja) русский (ru) 中文（中国大陆）‎ (zh_CN)

## 用法

### 长度

Extended Pascal 为此定义了“模式”的概念。 Delphi 引入了“动态数组”。 截至 2020 年，FPC 仅支持后者关于可变长度数组，同时计划支持“模式”。

```array[indexType] of baseType
```

```array of baseType
```

#### 静态数组

``` 1program staticArrayDemo(input, output, stderr);
2
3type
4	// specifying ordinal types as index directly
5
6	/// allows selection of a character
7	/// based on a Boolean value
8	characterChoice = array[boolean] of UCS4char;
9
10	// enumerations
11
12	/// enumerates Cartesian axes
13	spaceAxis = (xAxis, yAxis, zAxis);
14	/// a point in three-dimensional Euclidean space
15	locus = array[spaceAxis] of valReal;
16	/// a point in a two-dimensional Euclidean plane
17	point = array[xAxis..yAxis] of valReal;
18
19	// integer subranges
20
21	level = array[-24..24] of longint;
22	box = array[-1..1, -1..1, -1..1] of boolean;
23	transformationMatrix = array[0..1, 0..1] of valReal;
24begin
25end.
```

As all array’s elements have to be addressable, there exists a maximum limit of elements an array can hold. The `sizeOf` every array type has to be less than `ptrInt`’s maximum value.

### 寻址元素

```1program arrayAddressDemo(input, output, stderr);
2var
3	msg: array[0..2] of char;
4begin
5	msg[0] := 'H';
6	msg[1] := 'i';
7	msg[2] := '!';
8	writeLn(msg);
9end.
```

```arrayVariable[firstDimensionIndex, secondDimensionIndex, thirdDimensionIndex]
```

```arrayVariable[firstDimensionIndex][secondDimensionIndex][thirdDimensionIndex]
```

```program arrayAddressOrderDemo(input, output, stderr);
{\$rangeChecks on}
var
i: integer;
f: array[0..1, 0..3] of boolean;
begin
for i := 0 to 7 do
begin
f[0, i] := true;
end;
end.
```

## 应用程序

In the default RTL’s system unit the function `system.slice` returns the initial part of an array, similiar to Ruby’s notation `arrayVariable[0, n]`. Furthermore there is `system.arrayStringToPPchar`. Most statistical routines of the RTL’s math unit accept arrays as parameters, as well as some other routines.