IPB

> Array-type constants
Чат
Форум
Загрузка...
 

Language:
Русский
English

  Array-type constants


The declaration of an array-type constant specifies the values of the components.

The component type of an array-type constant can be any type except a file type.

Example

 type
   Status = (Active, Passive, Waiting);
   StatusMap = array[Status] of string[7];
 const
   StatStr: StatusMap = ('Active', 'Passive', 'Waiting');

{ These are the components of StatStr

   StatStr[Active] = 'Active'
   StatStr[Passive] = 'Passive'
   StatStr[Waiting] = 'Waiting' }

Character arrays

Packed string-type constants (character arrays) can be specified both as single characters and as strings. For example, this definition:

   const
     Digits: array[0..9] of Char = ('0', '1', '2', '3', '4', '5',
       '6', '7', '8', '9');

can be expressed more conveniently as:

   const
     Digits: array[0..9] of Char = '0123456789';

Zero-based character arrays

A zero-based character array is one in which the first element is 0 and the last element is a positive non-zero integer. For example:

   array[0..X] of Char

When you enable the extended syntax (with a {$X+} compiler directive), a zero-based character array can be initialized with a string that is shorter than the declared length of the array. For example:

   const
     FileName = array[0..79] of Char = 'TEST.PAS';

When the string is shorter than the array's length, the remaining characters are set to NULL (0) and the array will effectively contain a

Multidimensional array constants

Multidimensional array constants are defined by enclosing the constants of each dimension in separate sets of parentheses, separated by commas.

The innermost constants correspond to the rightmost dimensions.

For example, this declaration:

   type
     Cube = array[0..1, 0..1, 0..1] of Integer;
   const
     Maze: Cube = (((0, 1), (2, 3)), ((4, 5), (6, 7)));

provides an initialized array Maze with the following values:

   Maze[0, 0, 0] = 0
   Maze[0, 0, 1] = 1
   Maze[0, 1, 0] = 2
   Maze[0, 1, 1] = 3
   Maze[1, 0, 0] = 4
   Maze[1, 0, 1] = 5
   Maze[1, 1, 0] = 6
   Maze[1, 1, 1] = 7

 
 К началу страницы 
 

Код для вставки: :: :: :: ГОСТ ::
Поделиться: //
 



-
Хостинг предоставлен компанией "Веб Сервис Центр" при поддержке компании "ДокЛаб"