|
Tip>Designer |
|
|
Working with collections |
|
|
Article #: |
0041 |
|
Contributor: |
Daniel Todes |
|
GF version: |
All |
|
Applies to: |
Collections |
|
Last updated: |
May 31, 2002 |
Description
At run time, create an array (collection) and dynamically add text as items that can be retrieved and manipulated elsewhere in the template.
Explanation
Follow the procedure below to create a collection at run time:
Create a new Dialog object that is a collection:
e.g.%[MyArray=CreateObject('GFDialogObject.DialogObject')] %[MyArray.isacollection=True]
At this stage the collection is empty. Populate the new collection with items:
e.g.%[MyArray.Add("Fred")]
%[MyArray.Add("Jim")]
%[MyArray.Add("Bob")]
Now you can manipulate the information in the collection from your template, for example:
Return the number of items in the collection:
%[MyArray.Count]
Return a specific item from the collection:
%[MyArray[2]]
Iterate over the items in the array/collection in one of two ways:
Option 1 (using "ForEachBlock")
e.g.%[ForEachBlock('X',MyArray.Count)]
%[MyArray[i]]%[i=i+1]%[EndBlock()]
Option 2 (using "RepeatBlockWhile")
e.g.%[i=1]%[RepeatBlockWhile(i<=MyArray.Count)]%[MyArray[i]]%[i=i+1]%[EndBlock()]