From Free Pascal wiki
Jump to: navigation, search

Deutsch (de) English (en) français (fr) Bahasa Indonesia (id)

An array is a type that groups a number of variables of the same type. Example are an array of char, integer, real or any other type including user defined types.

Different types of variables cannot be grouped into an array. For this purpose, see records.

The declaration works similar to that for simple types, but you need to add the number of elements & basic type.

The simplest way is as follows - it defines a so-called static array:

  variablename: array [startindex..endindex] of type;

startindex must be less than or equal to endindex, and both must resolve to an integer constant, either an integer value or a const value that is an integer. Either or both numbers may be negative or zero.

Simple example:

  simple_integer_array = array [1..10] of integer;
  Numbers: simple_integer_array;

More complex example:

  more_complex_array = array [0..5,1..3] of extended;
  specialmatrix: more_complex_array;

Arrays reflect the mathematical concept of

  • vectors (one-dimensional array) and
  • matrices (two-dimensional array)

multidimensional array are supported such as [x..y,z..t] and so on.

To call a variable you have to put the name of the array and the position a[1..3] and you can use it as a simple variable, but if you want to use parameters you MUST use a structure because else it will cause errors or bugs... (I do not understand, what is meant here).

If it is not possible to know the number of elements at the time of the program compilation, the dynamic array type can be used.

Data Types
Simple Data Types Boolean | Byte | Cardinal | Char | Extended | Int64 | Integer | Longint | Pointer | Real | Shortint | Smallint | Word
Complex Data Types Array | Class | Record | Set | String