1. Pete Yankovich
  2. PowerBuilder
  3. Thursday, 10 June 2021 20:33 PM UTC

Is there a way to dynamically change menu item event code?

The Retrieve menu item has this code in clicked event,

of_SendMessage ("pfc_retrieve")

I'd like to change that code to reference another event of the DW.  There are other DW's on the screen with code in the pfc_retrieve event and I want to ensure that the correct DW event is being called when Retrieve is clicked.

This is code I've used to change tool bar item text.

im_MenuId = MenuId

m_pts_sheet lm_menu
lm_menu = im_MenuId
lm_menu.m_edit.m_undo.toolbaritemtext = "Reset"

Thanks for any help.

John Fauss Accepted Answer Pending Moderation
  1. Friday, 11 June 2021 13:51 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Pete -

Since scripts are compiled, PowerScript code (events & functions) is quite different from changing object properties as you showed in your sample - so scripts cannot be defined dynamically. However, there is a simple way to accomplish what you want to do:

Unless there already exists at some point in this window's ancestor hierarchy, a PFC window by default does NOT contain a pfc_Retrieve event.

Via of_SendMessage(), the pfc_MessageRouter event in pfc_w_master will first attempt to execute the requested "pfc_retrieve" event to the window. If that fails (and it typically does fail silently since a window does not normally contain an event named "pfc_retrieve"), then the event request is sent to the GraphicObject that has focus. If that fails, the event is triggered in the last active DataWindow. If that fails, no action is performed.

All you should need to do to accomplish what you want to do is add an unmapped user event (which takes no argument parameters) in the window named pfc_retrieve. In that event script, code the custom logic you wish to have performed.

If for some reason any of the window's ancestors already contains a pfc_Retrieve event, override the ancestor script.

Best regards,
John

Comment
  1. Pete Yankovich
  2. Friday, 11 June 2021 17:19 PM UTC
Thanks John,

I followed your suggestion for the most part and everything is working as I want now. I appreciate your input.

Pete
  1. Helpful
There are no comments made yet.
Matt Balent Accepted Answer Pending Moderation
  1. Friday, 11 June 2021 02:09 AM UTC
  2. PowerBuilder
  3. # 2

That PFC code basically calls an event (pfc_retrieve in your example) on either the sheet (MDI app) or the menus parent window.  You can create another event on whatever window you want and use the same methodology (of_sendmessage method call) or trigger the event directly. 

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.