Add Items to Collections

Visual LANSA

Add Items to Collections

How you add items to collections depends on the type of collection you are using.

To add items to a keyed collection with Style(Factory) you simply refer to an item in the collection. If an item with the specified key does not exist,  it is created automatically. For example setting the properties of  button #Button_Factory<1> creates it if it does not already exist:

Set Com(#Button_Factory<1> Parent(#Com_Owner) Height(20) Width(100) Left(2) Top(#Next_Top) Caption('Factory Button')
 

To add items to a keyed collection with Style(Collection) and to any other ordered collection such as array or list collection, you explicitly create the object either with a SET_REF *create_as or with a DEFINE_COM statement and a  SET_REF.

This code adds a button to a keyed collection with Style(Collection):

Set_Ref Com(#Button_Collection<#Use_Key>) To(*create_as #Prim_Phbn)
Set Com(#Button_Collection<#Use_Key>) Parent(#Com_Owner) Height(20) Width(100) Left(2) Top(#Next_Top) Caption('Collection Button')
 

This method routine creates buttons:

Mthroutine Name(CreateButton)
Define_Map For(*Input) Class(#Std_Num) Name(#TheKey)
Define_Com Class(#Prim_phbn) Name(#Button)
Set_Ref Com(#Button_Collection<#TheKey>) To(#Button)
Endroutine

 

All other collections except keyed collections have Insert methods to add items to the collection. The item to be inserted in the collection has to be created before it is inserted. This code adds #EmployeeNumbers to a collection named #PayLoadList:

Define_Com Class(#Prim_ALPH) Name(#EmployeeNumber) Reference(*Dynamic)
.
Set_Ref Com(#EmployeeNumber) To(*Create_as #Prim_ALPH)
Set Com(#EmployeeNumber) Value(#EmpNo)
Invoke Method(#PayLoadList.Insert) Item(#EmployeeNumber)

 

Ý 6.22.5 Collection Programming Summary