System.ArrayLen(Array of [Any] [, Integer]) Method

Version: Available or changed with runtime version 1.0.

Returns the total number of elements in an array or the number of elements in a specific dimension.

Syntax

Length :=   System.ArrayLen(Array: Array of [Any] [, Dimension: Integer])

Note

This method can be invoked without specifying the data type name.

Parameters

Array
 Type: Any
The array that you want to investigate.

[Optional] Dimension
 Type: Integer
If you omit this optional argument, the method returns the total number of elements in the array. To get the number of elements in a specific dimension, use Dimension with a valid value. The valid values are determined by the number of dimensions of the input array. For example, the valid values for a three-dimensional array would be 1, 2, and 3.

Return Value

Length
 Type: Integer

Remarks

If you use ArrayLen with an input parameter that is not an array, a run-time error occurs.

Example

This example shows how to use the ArrayLen method.

var
    Array1: array[2] of Integer;
    Array2: array[3,4] of Integer;
begin
    Message('Array1, Total number of elements: %1', ArrayLen(Array1));  
    Message('Array2, Dimension 1 size: %1', ArrayLen(Array2,1));  
    Message('Array2, Dimension 2 size: %1', ArrayLen(Array2,2));  
    Message('Array2, Total number of elements: %1', ArrayLen(Array2));  
end;

The following messages are displayed.

Array1, Total number of elements: 2

Array2, Dimension 1 size: 3

Array2, Dimension 2 size: 4

Array2, Total number of elements: 12

See Also

System Data Type
Get Started with AL
Developing Extensions