&<img src="../resources/images/opentocr.png" title="Open Contents list" border="0"&>
You are here:

Array Collection Example

This example shows how to use an array collection to store and look up information. The aim of the example is to show in a simple context the basic techniques of using array collections. In real situations you would implement an array collection with large amounts of data for performance reasons.
Array collections are a dynamically sized, ordered collection of components that can be located by indexing. Indexing is always relative to 1.
In this example Department Code, Employee Salary and Zip Code information is stored in an array collection. When an employee is selected in the list view, this information is retrieved from the array collection.

Define the Collections
The tree array collections used to keep collections of  departments, salaries and post/zip codes are defined like this:
Define_Com Class(#Prim_ACol<#Deptment>) Name(#Department_Array)
Define_Com Class(#Prim_ACol<#Salary>) Name(#Salary_Array)
Define_Com Class(#Prim_ACol<#PostCode>) Name(#PostCode_Array)
The collection definitions specify the type of object to be collected and the name of the collection.
Add Items to the Collections
In order to add items to the collection, you need to first create the instances of the objects to be inserted:
 
Define_Com Class(#Deptment) Name(#Department_Item)
Define_Com Class(#Salary) Name(#Salary_Item)
Define_Com Class(#PostCode) Name(#PostCode_Item)
After the objects have been created, their value is set and they are added to the collections using the Insert method:
Set Com(#Department_Item) Value(#Deptment)
Invoke Method(#Department_Array.Insert) Item(#Department_Item)
Set Com(#Salary_Item) Value(#Salary)
Invoke Method(#Salary_Array.Insert) Item(#Salary_Item)
Set Com(#PostCode_Item) Value(#PostCode)
Invoke Method(#PostCode_Array.Insert) Item(#PostCode_Item)
Retrieve the Values from the Collections
The values stored for an employee in the collections are retrieved when an employee is selected in the list.  The array collections are in the same order as the entries in the list view so you can use the list view entry number as the index to get the values from the array collections:
 
Change Field(#USE_INDEX) To('#EMP_LIST.CURRENTITEM.ENTRY')
The values in the array collection are then assigned to the Department, Salary and PostCode fields:
 
Set Com(#Deptment) Value(#Department_Array.Item<#Use_Index>.Value)
Set Com(#Salary) Value(#Salary_Array.Item<#Use_Index>.Value)
Set Com(#PostCode) Value(#PostCode_Array.Item<#Use_Index>.Value)
Source for the Example
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(298) Clientwidth(638) Height(325) Left(269) Top(107) Visualstyle(#VS_NORM) Width(646)