Get a Submenu In PowerBuilder
Getting a reference to the window’s menu is easily accomplished using the window’s MenuId property. But what if you want to get a reference to a submenu and all you have is a string with the menu’s name? This following function will do the trick:
Just pass this function your main menu (the root), the name of the submenu you are looking for, and it will return the submenu in a reference variable
1 2 | menu lm_edit f_GetSubMenu(This.MenuID, "m_edit", lm_edit) |
f_GetSubMenu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ////////////////////////////////////////////////////////////////////////////// // // Function: f_GetSubMenu // // Access: Public // // Description: Find and return a menu reference in a reference variable to the menu // which name’s matches the passed menu name string. Start looking at // the passed menu, and if it is not found, look at its submenus. // // This is a recursive function // // Arguments: menu am_menu_root // string as_menu_name // menu am_found ref // // Returns: boolean lb_found // ////////////////////////////////////////////////////////////////////////////// Boolean lb_found = False Integer li_ndx, li_sz String ls_root_menu_name ls_root_menu_name = am_menu_root.ClassName() as_menu_name = Trim(Lower(as_menu_name)) If ls_root_menu_name = as_menu_name Then am_found = am_menu_root lb_found = True End If li_ndx = 0 li_sz = UpperBound(am_menu_root.Item) Do While li_ndx < li_sz And Not lb_found li_ndx ++ lb_found = f_GetSubMenu(am_menu_root.Item[li_ndx], as_menu_name, am_found) Loop Return lb_found |
Good Luck!