Getting a Reference to a Submenu
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:
//////////////////////////////////////////////////////////////////////////////
//
// Function: of_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 = of_GetSubMenu(am_menu_root.item[li_ndx], as_menu_name, am_found)
loop
Return lb_found
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
of_GetSubMenu(this.MenuId, "m_edit", lm_edit)
Like this:
Like Loading...
August 1, 2009 -
Posted by rick130 |
1. PowerBuilder General, Menus, Powerscript | menu, powerscript, submenu
Good Work