VFW104 – Simple Keyed Collections
Introduction to Collections
Collections are conceptually similar to conventional arrays. In Visual LANSA, they constitute a very powerful way of grouping components of the same type. You can collect any Class of component in a Collection. Commonly used types of collections in Visual LANSA include:
- Keyed Collection
- List Collection
- Array Collection
- Sorted Array Collection.
In this exercise, you will use a keyed collection.
Elements in conventional arrays are accessed using the element's index position, usually a number. In Visual LANSA, an element in a Keyed Collection can be accessed through its numeric index position or using an alphanumeric string.
A keyed collection is defined using the following command:
DEFINE_COM CLASS(#PRIM_KCOL<<Collecting><Key Value>>) NAME(...) STYLE(...)
The important properties in a Keyed Collection are:
- The value #PRIM_KCOL defines the component as keyed collection.
- The class of component or class of each element in the group.
- The numeric or alphanumeric value that allows you to access one element in the collection.
- Factory (default) means a new instance of the type of component should be created whenever the collection is accessed. A Collection means a *Null reference is to be returned whenever the collection is accessed with a key that does not exist.
The Style of collection you choose to use depends on whether the information stored in the collection is going to be shared by other forms or components and also on what type of thing you are going to collect. Sometimes a working list or an array would provide the same functionality as a collection, but it is impossible to pass a working list or an array to another form or reusable component. Storing the data in a collection would solve this issue. If you want to collect bitmaps or radio buttons then a Keyed Collection is the only option. If you are collecting objects of any kind you should use a Style Collection. For example, when you define a component in an event routine and then place a reference to it in a collection Style Collection, when the routine terminates the object ceases to exist. Or, you can explicitly destroy the object by setting its reference to *NULL. You cannot do that to an object created in a Style Factory collection. The object would exist in memory until the application is closed.
List collections are defined by using the following command:
DEFINE_COM CLASS(#PRIM_LCOL<< Collecting >>) NAME(...)
The important properties in a list collection are:
- The value #PRIM_LCOL defines the component as a list collection.
- The class of component or class of each element in the group.
Objective
- To learn about using keyed collections.
- To develop an command handler for Sections, which displays images for the employees in the section.
- To use the VL Framework method to link an employee image component to the Employee business object command handler.
To achieve these objectives you will complete the following steps:
Step 1. Create the Employee Images for Section Command Handler
Step 2. Create an Employee Image Component
Step 3. Make Sections Business Object Visible
Step 4. Implement the Employee Image component.
Step 5. Record the Switch History using the Virtual Clipboard
Step 6. Use the Switch History to Return to the Original BO
Before You Begin
This exercise depends on VFW080 – Using an Explorer Component, which maintains employee image records in file iiiEmpImages.