Using Dictionary object in Elipse E3.

The Dictionary object is a data structure defined as an “associative array”. Unlike common arrays, whose elements are linked via an integer, dictionary elements are accessed via keys, and its values can be either integer or strings.

Dictionaries are useful for storing and retrieving data, working as name/value pairs (referred to as “key” and “item”, respectively) in arrays. The key is a unique identifier for the corresponding item and cannot be used for any other item in the same Dictionary object.

The Dictionary’s main operations are:

Creating a dictionary and storing its contents in E3

The contents of a dictionary can be stored in an internal tag, similarly to what happens to arrays (KB-30127: Using an internal tag as vector (Array)).


Adding items to a dictionary

To add items to a dictionary, use Add ,.

To avoid script error in case the script above is executed again (there is a bug when you try to add pre-existing keys), use Exists to check if the key has already been added.

Querying data stored in a dictionary

The image above illustrates how to retrieve contents from a pre-existing key; if the key is non-existent, the script returns error. Therefore, similarly to Add function, where you can detect whether a key exists, this comparison for querying keys can be done in the same way:

Scanning items in a dictionary



Scanning keys in a dictionary

Removing a key from a dictionary


Removing all keys from a dictionary

The demo application attached to this article was developed with Elipse E3 v. 4.6 build 162, and illustrates all the functions described above.


Reference:

DevGuru

Attachments:

TestDictionary.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *