IVZDataArray.Add

Syntax

Add(Value: Variant): Integer;

Parameters

Value. A new element of data array.

Description

The Add method adds a new element to data 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 data array and add elements to it. Display array size, insert a new element into the position with index 2 using the InsertAt method and display it, then display array size. Remove the element with index 2 using the Remove method and display array size. Clear array using the Clear method and display its size:

Sub UserProc;
Var
    Array: IVZDataArray; // Array
Begin
    // Create new array and add elements to it
    Array := New VZDataArray.Create;
    Array.Add("Item1");
    Array.Add("Item2");
    Array.Add("Item3");
    // Output array size
    Debug.WriteLine("Array size: " + Array.Count.ToString);
    // Display elements item with index 2
    Debug.WriteLine("Array item with index 2: " + Array.Item(2));
    // Add new elements into array into position 2 
    Array.InsertAt(2,"Item4");
    Debug.WriteLine("Item added");
    // Display array element with index 2
    Debug.WriteLine("Array item with index 2: " + Array.Item(2));
    // Output array size
    Debug.WriteLine("Array size: " + Array.Count.ToString);
    // Remove array element
    Array.Remove(2);
    Debug.WriteLine("Item removed");
    // Output array size
    Debug.WriteLine("Array size: " + Array.Count.ToString);
    // Clear array
    Array.Clear;
    Debug.WriteLine("Array cleared");
    // Output array size
    Debug.WriteLine("Array size: " + Array.Count.ToString);
End Sub UserProc;

After executing the example, the development environment console window shows size and type of the created array, the element with index 2 after it was added and removed, and array size after it was cleared:

Array size: 3.

Array item with index 2: Item3.

Item added.

Array item with index 2: Item4.

Array size: 4.

Item removed.

Array size: 3.

Array cleared.

Array size: 0.

See also:

IVZDataArray