Array
Definition
An array is a single or multidimensionnal table of data.
Each data is called an element and is accessed by its position. The position is called INDEX.
Examples :
A string is a one dimension array :
chaine : array[1..8] of char;
A chessboard could be an 2D array
chessboard : array[1..8,1..8] of byte;
How to declare an Array
As seen previously, an array is defined with the keyword ARRAY.
An array could be a variable, a constant or a type. The type of the data must be declared
Array as a variable :
Example :
VAR
myTab : array[1..10] of byte;//10 bytes array
Array as a constant :
Example :
CONST
Days : array[1..7] of string =('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
Array as a type :
Example :
TYPE
TDays : array[1..7] of string;
CONST
Days : TDays = ('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
How to use an Array
Access to the cells
The index helps to access to the different cells.
Example (with the array Days) :
For i:=1 to 7 DO writeln(Days[i]);
Change a data value
Example (with the array myTab) :
myTab[2]:=10;
Array of a record
It's also possible to declare an array of a record :
Example :
TYPE TVerb = RECORD
infinitive:string[25];
past:string[25];
participle:string[25];
end;
VAR
irregular : array[1..100] of TVerb;