IVZLongArray.Add

Syntax

Add(Value: Integer): Integer;

Parameters

Value. New array element.

Description

The Add method adds a new element to array.

Example

The module containing the example should have link to the Visualizators assembly.  The specified procedure should be called from the Main entry point.

Create a new long-integer array and add elements to it. Insert a new element into the position with index 3 and remove the element from the position with index 2. Display the sum of all array elements. Then clear the array and display its size:

Sub UserProc;
Var
    Array: IVZLongArray; // Long-integer array
    i: Integer; // Counter
    Sum: Double; // Sum of elements
Begin
    // Create new array and add elements to it
    Array := New VZLongArray.Create;
    Array.Add(50535648);
    Array.Add(60145664);
    Array.Add(70445645);
    // Insert new element to position with index 2
    Array.InsertAt(280447321);
    // Remove element from position with index 0
    Array.Remove(0);
    // Display element value in position with index 2
    Debug.WriteLine("Item in position with index 2: " + Array.Item(2).ToString);   
    // Display sum of all array elements
    Sum := 0;
    For i := 0 To Array.Count - 1 Do
        Sum := Sum + Array.Item(i);
    End For;
    Debug.WriteLine("Sum of all array elements: " + Sum.ToString);
    // Clear array
    Array.Clear;
    // Output array size
    Debug.WriteLine("Array size after clearing: " + Array.Count.ToString);
End Sub UserProc;

After executing the example, the development environment console window shows value of the array element in position with index 2, the sum of all array elements and array size after it is cleared:

Element in position with index 2: 70445645

Sum of all array elements: 211038630

Array size after clearing: 0

See also:

IVZLongArray