IVZDoubleArray.Add

Syntax

Add(Value: Double): 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 system assembly.  The specified procedure should be called from the Main entry point.

Create a new array of real numbers with double precision 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: IVZDoubleArray; // Real numbers array
    i: Integer; // Counter
    Sum: Double; // Sum of elements
Begin
    // Create new array and add elements to it
    Array := New VZDoubleArray.Create;
    0Array.Add(50.535648);
   1 Array.Add(60.145664);
   2 Array.Add(70.445645);
    // Insert new element to position with index 2
    Array.InsertAt(280.447321);
    // 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:

Item in position with index 2: 70.445644999999999

Sum of all array elements: 211.03863000000001

Array size after clearing: 0

See also:

IVZDoubleArray