Factory and Collection Style Example

Visual LANSA

Factory and Collection Style Example

This example shows you the difference between coding factory and collection style collections.

The factory buttons are automatically created when the properties of the buttons are set:

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

 

The collection buttons are explicitly created using a SET_REF command after which the properties of the buttons are set:

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')
 

In both styles of collection the buttons are made visible by using the Realize method:

Invoke Method(#Button_Collection<>.Realize)

 

Source for the Factory/Collection Example

 

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(383) Clientwidth(182) Height(410) Left(452) Top(63) Visualstyle(#VS_NORM) Width(190)
 
* Style(Factory) and Style(Collection) collections
 
* Define a Style(Factory) keyed collection of buttons
 
Define_Com Class(#Prim_kCol<#Prim_PHBN #Std_Num>) Name(#Button_Factory)
 
* Define a Style(Collection) keyed collection of buttons
 
Define_Com Class(#Prim_kCol<#Prim_PHBN #Std_Num>) Name(#Button_Collection) Style(Collection)
 
* Form layout is 2 buttons to initiate the creation of collection of buttons
 
Define_Com Class(#PRIM_PHBN) Name(#PHBN_FACTORY) Caption('Make 3 Factory Buttons') Displayposition(2) Left(16) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(137)
Define_Com Class(#PRIM_PHBN) Name(#PHBN_COLLECTION) Caption('Make 3 Collection Buttons') Displayposition(1) Left(16) Parent(#COM_OWNER) Tabposition(2) Top(40) Width(137)
 
* Incrmental value used to position buttons
 
Define Field(#NEXT_TOP) Reffld(#STD_NUM) Default(80)
 
Define Field(#USE_KEY) Reffld(#STD_NUM)
 
* ----------------------------------------------------------------------
* #PHBN_FACTORY : Create 3 more buttons in the Style(Factory) collection
* ----------------------------------------------------------------------
 
Evtroutine Handling(#PHBN_FACTORY.Click)
 
Begin_Loop To(3)
 
* Get the next key to be used
 
Change Field(#USE_KEY) To('#Button_Factory.ItemCount + 1')
 
* Create the button simply by referencing it. Since the item does
* not exist in the collection and the collection is Style(Factory)
* then a new button will be automatically ""manufactured" .....
 
Set Com(#Button_Factory<#Use_Key>) Parent(#Com_Owner) Height(20) Width(100) Left(2) Top(#Next_Top) Caption('Factory Button')
 
* Increment the next top position
 
Change Field(#NEXT_TOP) To('#Next_Top + 26')
End_Loop
 
* Now that the buttons have been created make them visible by realizing them
Invoke Method(#Button_Factory<>.Realize)
 
Endroutine
 
* ----------------------------------------------------------------------------
* #PHBN_COLLECTION : Create 3 more buttons in the Style(Collection) collection
* -----------------------------------------------------------------------------
 
Evtroutine Handling(#PHBN_COLLECTION.Click)
 
Begin_Loop To(3)
Change Field(#USE_KEY) To('#Button_Collection.ItemCount + 1')
 
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')
 
Change Field(#NEXT_TOP) To('#Next_Top + 26')
 
End_Loop
 
* Now that the buttons have been created make them visible by realizing them
Invoke Method(#Button_Collection<>.Realize)
 
Endroutine
 
End_Com

 

Ý Factory and Collection Style Collections