|
|
|
NOTE: This Design document is subject to change at any time. |
Collection
Syntax: <COLLECTION property-list/>
A Collection is a list of objects and is compatible with the standard COM Collection object. The objects in the collection can be of any type, and you can even mix different types within a single collection. An object can even be another collection to create multi-dimensional arrays.
Objects in the collection are retrieved by an index, which starts at 1 (the Base of the collection can be changed).
In addition to being a valid zApp component using the above tag, many zApp functions and routines use Collections. You can also create a collection using the core.CreateObject("Collection","") routine.
Collections are compatible with the "foreach" statement in scripting languages such as VBScript. Collections also implement associative arrays, or key=value lists, although for more robust key/value storage you can also use a zStore object instead of a Collection.
Collections maintain an internal update notification list and can notify other zApp components that use the collection when the collection is modified. For example, when a collection is added to a zGrid component, the grid is refreshed when a new item is added to the collection.
Examples:
Adding items to a collection:
Code: |
Collection.Add( "Item1")
Collection.Add("Item2")
Collection.Item(1) = "New Item1" |
Looping through a collection:
Code: |
for i = 1 to Collection.Count
S = Collection.Item(i)
next |
Looping through a collection regardless of index values:
Code: |
for each S in Collection
msgbox S
next |
Using a collection as an associative array:
Code: |
Collection.Value("name") = "Zugg"
Collection.Value("mode") = 1
msgbox Collection.Value("name") |
|
|