Creating handles for a menu

IanC74

Member
Hi, Im trying to create a menu for a small group of screens which is controlled by a menu definitions table. So basically i create a menu structure from the labels/exec/direcoties defined in that table.

It works fine for a single level, i.e. using hmenu, hsubmenu and hsubmenuitem handles to control the top level menu, submenu off that menu and items for the menus.

However, if i want to create another level of submenus and submenuitems (so i can have another submenu on a submenu) i would need to define another 2 handles for that submenu and its submenuitems.

Thats ok, but if i wanted to be dynamic and have further submenus later without changing code i dont want to have to create numbers of handles in the code, but create them at run time.

Is this possible, i.e. craete a variable and assign the handle name to the variable and create the handle name from value(handvariable)?

Hope this makes sense!

TIA

Ian
 

GregTomkins

Active Member
As usual I am not 100% sure I understand (it's me, not you), but:

You cannot dynamically create variables per se. Greg Higgins suggested this at a conference once and I thought, "wow what a great idea!", but AFAIK nothing ever came of it.

However, you could create a dynamic temp-table and then create handle fields inside that. You can do all sorts of crazy stuff such as a DTT containing handles to other DTT's, so I am pretty sure this would work for menus too.
 

IanC74

Member
Thanks Greg, hmm thats interesting about the dynamic temp table. Do you know of any examples of DTT with handles? Sorry for being a pain, im almost ready to pull my hair out (whats left of it!).

Ian

As usual I am not 100% sure I understand (it's me, not you), but:

You cannot dynamically create variables per se. Greg Higgins suggested this at a conference once and I thought, "wow what a great idea!", but AFAIK nothing ever came of it.

However, you could create a dynamic temp-table and then create handle fields inside that. You can do all sorts of crazy stuff such as a DTT containing handles to other DTT's, so I am pretty sure this would work for menus too.
 

GregTomkins

Active Member
Actually I looked into our code that does menus and maybe the DTT suggestion was silly. Our menu system is 100% table driven and it definitely supports nested menus though I'm not sure if they can be arbitrarily deep. Here is an edited version of the code we use:

RUN get_menu_items ON SERVER(OUTPUT tmp_user_menu_item):

FOR EACH tmp_user_menu_item NO-LOCK
CREATE SUB-MENU h_cascading_menu_item_hdl
ASSIGN PARENT = h_submenu_item_hdl
LABEL = tmp_user_menu_item.menu_label
PRIVATE-DATA = tmp_user_menu_item.proc_name.

FOR EACH bf_tmp_user_menu_item NO-LOCK
WHERE bf_tmp_user_menu_item.sub_menu_key = tmp_user_menu_item.cascading_key:

CREATE MENU-ITEM h_menu_item_hdl
ASSIGN PARENT = h_cascading_menu_item_hdl
LABEL = bf_tmp_user_menu_item.menu_label.

/*store the procedure name in the private data to be run when the user selects the menu item,
along with the toggle state*/
h_menu_item_hdl:pRIVATE-DATA = bf_tmp_user_menu_item.proc_name.

The reason my DTT suggestion might have been silly is, I don't think we actually care about the menu handles once they have been created. We stuff an identifier into PRIVATE-DATA, set them all to run a common handler, and then use PRIVATE-DATA to figure out what to do.

I do not claim this to be perfect or the only way, and I didn't write this!!, but it seems to work OK for us...
 

IanC74

Member
Hi Greg, thanks for all your help. I think I was on the right track with my menus after looking at your code, i think i see where I was going wrong.

Really appreciate your help.

Thank you
Ian
 
Top