IVZDataDictionary.Add

Fore syntax

Add(Key: String; Value: Variant);

Fore.NET syntax

Add(Key: string; Value: object);

Parameters

Key. Key of the element to be added.

Value. New dictionary element.

Description

The Add method adds a new element to dictionary.

Comments

To remove element, use the IVZDataDictionary.Remove method.

Fore example

Add a link to the Visualizators system assembly.

Sub UserProc;
Var
    Dictionary: IVZDataDictionary;
    i: Integer;
   Key: Variant;
Begin
    // Create a new dictionary and add elements to it
    Dictionary := New VZDataDictionary.Create;
    Dictionary.Add("Key 1"25);
    Dictionary.Add("Key 2""Element value");
    Dictionary.Add("Key 3"2.4);
    // Remove element in position with the set key
    Dictionary.Remove("Key 3");
    // Output dictionary size
    Debug.WriteLine("Dictionary size: " + Dictionary.Count.ToString);
    // Output a list of all keys and values of dictionary elements
    Debug.WriteLine("Dictionary:");
    For i := 0 To Dictionary.Count - 1 Do
       Key := Dictionary.AllKeys.Item(i);
        Debug.WriteLine(Key + " " + Dictionary.Item(Key));
    End For;
    // Clear dictionary
    Dictionary.Clear;
End Sub UserProc;

After executing the example a new data dictionary is created that contains three elements. Then the element with the Key 3 key is removed from the dictionary. The console window displays dictionary size and the list of all keys and values of its elements. After executing all the operations the dictionary is cleared.

Fore.NET example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Visualizators;

Public Shared Sub Main(Params: StartParams);
Var
    Dictionary: IVZDataDictionary;
    i: Integer;
   Key: Object;
Begin
    // Create a new dictionary and add elements to it
    Dictionary := New VZDataDictionary.Create();
    Dictionary.Add("Key 1"25);
    Dictionary.Add("Key 2""Element value");
    Dictionary.Add("Key 3"2.4);
    // Remove element in position with the set key
    Dictionary.Remove("Key 3");
    // Output dictionary size
    System.Diagnostics.Debug.WriteLine("Dictionary size: " + Dictionary.Count.ToString());
    // Output list of all dictionary keys and values
    System.Diagnostics.Debug.WriteLine("Dictionary:");
    For i := 0 To Dictionary.Count - 1 Do
       Key := Dictionary.AllKeys.Item[i];
        System.Diagnostics.Debug.WriteLine(Key + " " + Dictionary.Item[Key]);
    End For;
    // Clear dictionary
    Dictionary.Clear();
End Sub;

See also:

IVZDataDictionary