Page History
この例では、リスト・ビューの選択されたエントリーに対応するメニュー・アイテムのコレクションを作成する方法を説明します。
[ |../../index.htm#lansa/l4wdev06_1055.htm]
現在地:
...
この例では、リスト・ビューの選択されたエントリーに対応するメニュー・アイテムのコレクションを作成する方法を説明します。
アイコンがメニューで選択されると、リスト・ビューで選択解除されます。
コレクションの定義
この例では、Collectionスタイルのコレクションを使用し、メニュー・アイテム・コレクションにメニュー・アイテムを追加します。メニュー・アイテムのコレクションは、以下のように定義されます。
Define_
...
Com Class(#PRIM_KCOL<#PRIM_
...
MITM #EMPNO>) Name(#MENU_ITEMS)
...
Collects(#PRIM_MITM)
...
Keyedby(#EMPNO)
...
Style(Collection)
...
- コレクションのNameは#MENU_ITEMS
- コレクションは、メニュー・アイテム(#PRIM_MITM)を格納
- Keyedbyプロパティは、コレクションのキーに使用されるリポジトリ・フィールド(#EMPNO)を指定
- Styleは、Collection
サブメニュー
メニュー・アイテムを含むサブメニューが定義されますが、最初はメニュー・アイテムが含まれず、動的な参照で定義され、サブメニューは参照が明示的に設定されたときにのみ作成されるので、メニュー・タイトルと関連付けられません。
DEFINE_
...
COM class(#PRIM_SMNU)
...
name(#Sub_menu)
...
reference(*dynamic)
...
コレクションへのアイテムの追加
リストの社員が選択されると、MENU_ITEMSコレクションにメニュー・アイテムが追加されます。
Evtroutine Handling
Evtroutine Handling(#LTVW_1.ItemGotSelection)
...
Options(*
...
NOCLEARMESSAGES *NOCLEARERRORS)
...
* Create submenu item if it doesn't already exist
If_Ref Com(#Sub_menu)
...
Is(*null)
Set_
...
Ref Com(#Sub_menu)
...
To(*create_
...
as #prim_smnu)
...
Set Com(#Sub_menu)
...
Parent(#menu_title)
...
Endif
* Create menu item based on the employee details
Set_Ref Com(#menu_items<#empno>)
...
To(*create_
...
as #prim_mitm)
...
* Define menu item's text
Use Builtin(BCONCAT)
...
With_Args(
...
#EMPNO #GIVENAME #SURNAME) To_Get(#STD_TEXTL)
...
* Set menu item's properties
Set Com(#menu_items<#empno>)
...
Caption(#std_textl)
...
Parent(#Sub_menu)
...
Endroutine
コレクション内のアイテムの破棄
リストのエントリーが選択解除されると、参照が*NULLに設定され、メニュー・アイテムはメモリから破棄されます。
EVTROUTINE handling
EVTROUTINE handling(#LTVW_1.ItemLostSelection)
...
options(*
...
NOCLEARMESSAGES *NOCLEARERRORS)
SET_
...
REF com(#menu_items<#empno>)
...
to(*null)
ENDROUTINE
...
コレクションの例4のソース・コード
Collectionスタイルのコレクションの動作を見るには、このソースをコピーしてフォームに貼り付け、フォームをコンパイルして実行してください。
Function Options
Function Options(*DIRECT)
Begin_
...
Com Role(*
...
EXTENDS #PRIM_FORM)
...
Clientheight(310)
...
Clientwidth(393)
...
Height(356)
...
Layoutmanager(#ATLM_1)
...
Left(308)
...
Menubar(#MBAR_1)
...
Top(120)
...
Width(401)
Define_
...
Com Class(#PRIM_ATLM)
...
Name(#ATLM_1)
Define_
...
Com Class(#PRIM_ATLI)
...
Name(#ATLI_1)
...
Attachment(Center)
...
Manage(#LTVW_1)
...
Parent(#ATLM_1)
...
Define_
...
Com Class(#PRIM_MBAR)
...
Name(#MBAR_1)
...
Parent(#COM_OWNER)
Define_
...
Com Class(#PRIM_MITM)
...
Name(#MENU_TITLE)
...
Caption('
...
Selected Employees')
...
Displayposition(1)
...
Parent(#MBAR_1)
...
Define_
...
Com Class(#PRIM_LTVW)
...
Name(#LTVW_1)
...
Displayposition(1)
...
Fullrowselect(True)
...
Height(310)
...
Left(0)
...
Parent(#COM_OWNER)
...
Tabposition(1)
...
Top(0)
...
Width(393)
Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_1)
...
Displayposition(1)
...
Parent(#LTVW_1)
...
Source(#EMPNO)
...
Width(26)
Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_2)
...
Displayposition(2)
...
Parent(#LTVW_1)
...
Source(#SURNAME)
...
Width(38)
Define_
...
Com Class(#PRIM_LVCL)
...
Name(#LVCL_3)
...
Displayposition(3)
...
Parent(#LTVW_1)
...
Source(#GIVENAME)
...
Width(20)
...
Widthtype(Remainder)
...
* Collection of selected menu items
* STYLE(Collection) requires that the items in the collection are explicitly created at run time by the application
Define_Com Class(#PRIM_KCOL<#PRIM_
...
MITM #EMPNO>) Name(#MENU_ITEMS)
...
Collects(#PRIM_MITM)
...
Keyedby(#EMPNO)
...
Style(Collection)
...
* Submenu component required for menu items
Define_Com Class(#PRIM_SMNU)
...
Name(#Sub_menu)
...
Reference(*dynamic)
...
* Populate list view with known employees
Evtroutine Handling(#COM_OWNER.CreateInstance)
...
Options(*
...
NOCLEARMESSAGES *NOCLEARERRORS)
...
Select Fields(#LTVW_1)
...
From_File(PSLMST)
Add_
...
Entry To_List(#LTVW_1)
Endselect
...
Endroutine
* Create a menu item of selected employees
Evtroutine Handling(#LTVW_1.ItemGotSelection)
...
Options(*
...
NOCLEARMESSAGES *NOCLEARERRORS)
...
* Create submenu item if it doesn't already exist
If_Ref Com(#Sub_menu)
...
Is(*null)
Set_
...
Ref Com(#Sub_menu)
...
To(*create_
...
as #prim_smnu)
...
Set Com(#Sub_menu)
...
Parent(#menu_title)
...
Endif
* Create menu item based on the employee details
Set_Ref Com(#menu_items<#empno>)
...
To(*create_
...
as #prim_mitm)
...
* Define menu item's text
Use Builtin(BCONCAT)
...
With_Args(
...
#EMPNO #GIVENAME #SURNAME) To_Get(#STD_TEXTL)
...
* Set menu item's properties
Set Com(#menu_items<#empno>)
...
Caption(#std_textl)
...
Parent(#Sub_menu)
...
Endroutine
* When a list entry loses selection, destroy the menu item
Evtroutine Handling(#LTVW_1.ItemLostSelection)
...
Options(*
...
NOCLEARMESSAGES *NOCLEARERRORS)
Set_
...
Ref Com(#menu_items<#empno>)
...
To(*null)
...
Endroutine
* When an employee is selected in the menu, deselect it in the list
Evtroutine Handling(#menu_items<>.Click)
...
Com_Sender(#Selected_menu_items)
...
Define Field(#W_EMPNO)
...
Reffld(#EMPNO)
...
* Use menu item caption to find out which employee number this item represents
Change Field(#STD_TEXTL)
...
To('#Selected_menu_items.Caption')
...
Substring Field(#STD_
...
TEXTL 1 5) Into_Field(#W_EMPNO)
...
Selectlist Named(#LTVW_1)
...
Continue If('#w_
...
empno *ne #empno')
...
* Set this employee to be unselected
Set Com(#ltvw_1.currentitem)
...
Selected(false)
...
* Destroy the menu item
Set_Ref Com(#menu_items<#w_empno>)
...
To(*NULL)
Leave
Endselect
...
Endroutine
End_Com
