コレクションにアイテムを追加する方法は、使用しているコレクションのタイプによって異なります。
Style(Factory)のコレクションにアイテムに追加するには、コレクションのアイテムを参照するだけです。指定されたキーを持つアイテムが存在しない場合は、自動的に作成されます。例えば、ボタン#Button_Factory<1>のプロパティの設定で、存在しない場合は作成されます。
Set Com(#Button_Factory<1> Parent(#Com_Owner) Height(20) Width(100) Left(2) Top(#Next_Top) Caption('Factory Button')
Style(Collection)のコレクションと配列やリストなどの他の順序付けられたコレクションにアイテムを追加するには、明示的にSET_REF *create_asまたはDEFINE_COMステートメントとSET_REFでオブジェクトを作成します。
このコードは、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')
このメソッド・ルーチンは、ボタンを作成します。
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
コレクション以外のすべてのコレクションには、コレクションにアイテムを追加するInsertメソッドがあります。コレクションに挿入されるアイテムを、挿入前に作成する必要があります。このコードは、#EmployeeNumbersを#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)