[ |../../index.htm#lansa/l4wdev06_1055.htm]
現在地:

2.17.3.5 例4: メニュー・アイテムのコレクション

この例では、リスト・ビューの選択されたエントリーに対応するメニュー・アイテムのコレクションを作成する方法を説明します。

アイコンがメニューで選択されると、リスト・ビューで選択解除されます。
コレクションの定義
この例では、Collectionスタイルのコレクションを使用し、メニュー・アイテム・コレクションにメニュー・アイテムを追加します。メニュー・アイテムのコレクションは、以下のように定義されます。
Define_Com Class(#PRIM_KCOL<#PRIM_MITM #EMPNO>) Name(#MENU_ITEMS) Collects(#PRIM_MITM) Keyedby(#EMPNO) Style(Collection)
 

サブメニュー
メニュー・アイテムを含むサブメニューが定義されますが、最初はメニュー・アイテムが含まれず、動的な参照で定義され、サブメニューは参照が明示的に設定されたときにのみ作成されるので、メニュー・タイトルと関連付けられません。
DEFINE_COM class(#PRIM_SMNU) name(#Sub_menu) reference(*dynamic)
 
コレクションへのアイテムの追加
リストの社員が選択されると、MENU_ITEMSコレクションにメニュー・アイテムが追加されます。
 
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(#LTVW_1.ItemLostSelection) options(*NOCLEARMESSAGES *NOCLEARERRORS) SET_REF com(#menu_items<#empno>) to(*null) ENDROUTINE
 
コレクションの例4のソース・コード
Collectionスタイルのコレクションの動作を見るには、このソースをコピーしてフォームに貼り付け、フォームをコンパイルして実行してください。
 
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
 
[ |../../index.htm#lansa/l4wdev06_1055.htm]