Editar

Compartir a través de


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

Version: Available or changed with runtime version 1.0.

Copies one or more elements in an array to a new array.

Syntax

 System.CopyArray(NewArray: Array of [Any], Array: Array of [Any], Position: Integer [, Length: Integer])

Note

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

Parameters

NewArray
 Type: Any
The array to copy to; the destination array.

Array
 Type: Any

Position
 Type: Integer
The position of the first array element to copy.

[Optional] Length
 Type: Integer
The number of array elements to copy. If you do not specify Length, all array elements are copied from Position to the last element. Use the following equation to determine valid values. 1 =< LENGTH =< MAXLEN(ARRAY) - POSITION + 1

Remarks

You can only copy from one-dimensional arrays. Repeat the CopyArray method to copy two-dimensional and three-dimensional arrays.

You cannot copy an array if the data type of the array is a complex data type. For more information about complex data types, see AL Data Types.

Example 1

The following example assigns values to Array1 and copies values from Array1 to Array2. Array1 is an integer array with the Dimensions Property set to 10. It contains integers from 1 to 10. The example code copies the numbers 6, 7, 8, 9, and 10 to Array2, an integer array with the Dimensions property set to 5.

var
    Array1: array[10] of Integer;
    Array2: array[5] of Integer;
begin
    Array1[1] := 1;  
    Array1[2] := 2;  
    Array1[3] := 3;  
    Array1[4] := 4;  
    Array1[5] := 5;  
    Array1[6] := 6;  
    Array1[7] := 7;  
    Array1[8] := 8;  
    Array1[9] := 9;  
    Array1[10] := 10;  
    COPYARRAY(Array2,Array1,6,5);  
end;

Example 2

If Array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, and Array2 is an integer array with dimension 5, then the following command causes a run-time error.

CopyArray(Array2,Array1,3);  

The error occurs because the code attempts to copy eight elements from Array1 to Array2, and Array2 has room for only five elements.

System Data Type
Get Started with AL
Developing Extensions