Schultz’s PowerBuilder Notes

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[/sourcecode] 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)

August 1, 2009 - Posted by | 1. PowerBuilder General, Menus, Powerscript | , ,

1 Comment »

  1. Good Work

    Comment by Mohammad Al-Habibi | August 2, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: