1. Bjarne Anker
  2. PowerBuilder
  3. Friday, 3 November 2017 13:17 PM UTC

Is it possible to get a menuitem when I have the name in a variable?

I want to disable/enable certain menus based on which modules the user has access to.

All the menunames is stored in a table with the corresponding module number, and I'm writing a function to enable/disable the menus.

 

Regards,

Bjarne Anker

Accepted Answer
Arthur Hefti Accepted Answer Pending Moderation
  1. Friday, 3 November 2017 13:41 PM UTC
  2. PowerBuilder
  3. # Permalink
Hi
I use this recursive function on the menu. To start with I call it from the windows, passing MenuId and the string of the item to be found. This logic can be included/used in a menu function that enables/disables the menu item.
 
Regards
Arthur
 
of_FindMenuItem (menu am_current, string as_menuitem);/
******************************************
 Description   : Searches a menu item
 Parameters   : am_current: Current menu, as_menuitem: Menu item Name
 Returns        : menu
 ******************************************/
integer li_Counter, li_Max
menu lm_Item, lm_RetItem
 
li_Max = UpperBound( am_Current.Item )
FOR li_Counter = 1 TO li_Max
  lm_Item = am_Current.Item[li_Counter]
  IF lm_Item.ClassName() = as_menuitem THEN // Found
    RETURN lm_Item
  ELSE
    IF UpperBound( lm_Item.Item ) > 0 THEN
      lm_RetItem = of_FindMenuItem( lm_Item, as_MenuItem )
      IF NOT IsNull( lm_RetItem ) THEN
        RETURN lm_RetItem
      END IF
    END IF
  END IF
NEXT
SetNull( lm_Item )
RETURN lm_Item
Comment
  1. Bjarne Anker
  2. Friday, 3 November 2017 14:51 PM UTC
Thanks Arthur!



This functions is really helpful in how to understand how the menu is built up.

I can use it both for traversing the menu, and to enable/disable the menus I want.



 



Regards,



Bjarne

  1. Helpful
There are no comments made yet.
Bjarne Anker Accepted Answer Pending Moderation
  1. Friday, 3 November 2017 13:37 PM UTC
  2. PowerBuilder
  3. # 1

Nevermind, I found the solution shortly after posting the question.

There is a function in PFC, of_GetMenuReference(ref am_source, string find, ref menu) which returns a menu from the item name.

Works perfectly.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.