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:

  1. Create a new Dialog object that is a collection:

e.g.%[MyArray=CreateObject('GFDialogObject.DialogObject')] %[MyArray.isacollection=True]

  1. 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:

  1. Return the number of items in the collection:

%[MyArray.Count]

  1. Return a specific item from the collection:

%[MyArray[2]]

  1. Iterate over the items in the array/collection in one of two ways: