1. Suguna Thamaraiselvan
  2. PowerBuilder
  3. Thursday, 10 October 2024 02:36 AM UTC

Hi All,

I have a menu with some 25 submenus. Based on some configuration, during run time, I have to add some more submenus.

I created the submenu under the 25th menu and copied the properties from 25th menu. Submenus are created already.

Now, When I click the submenu, nothing happened. Because no code to trigger anything.

So, please advise me, where to write the code to trigger the clicked event of dynamically created menu?

Thank you.

Regards,

Suguna.

 

 

 

 

John Fauss Accepted Answer Pending Moderation
  1. Thursday, 10 October 2024 03:51 AM UTC
  2. PowerBuilder
  3. # 1

Hi, Suguna -

If you have not already done so, I suggest you download and carefully examine the DynamicMenus free code example at Roland Smith's TopWizProgramming web site:

    https://www.topwizprogramming.com/freecode_dynamicmenus.html

It shows one way that you can dynamically add items to menus and have the new menu items trigger an event in the window. Perhaps you can adapt the technique for your particular use.

Best regards, John

Comment
There are no comments made yet.
Suguna Thamaraiselvan Accepted Answer Pending Moderation
  1. Thursday, 10 October 2024 05:10 AM UTC
  2. PowerBuilder
  3. # 2

Hi John,

 

Thank you for your response.

Already Menus got created. I want only to trigger the clicked event.

Please advise on this.

 

Regards,

Suguna.

 

Comment
  1. John Fauss
  2. Thursday, 10 October 2024 14:19 PM UTC
I've already given you my advice: I previously suggested that you carefully examine how the DynamicMenus example app that Roland Smith has developed (and graciously provides for free) works. If you had taken a little time and effort to do this instead of summarily rejecting my suggestion, you may have learned one technique for accomplishing this. Rene's response provides the key point: You must create a user object that is inherited from the PB menu object and add properties and methods that will either call a window function or use TriggerEvent PowerScript function to fire an event in the parent window.

We do something similar where I work inside of our commercial application, but instead of calling a window function while using the "Dynamic" keyword to prevent compiler errors and to fail gracefully at runtime if the function does not exist, we elected to use an instance string variable in the dynamic menu object to hold an event name, then use TriggerEvent(is_event_name) in the parent window (which also fails gracefully if the event does not exist) to fire a user event in the window. While I'm unable to supply you with the proprietary code that implements this particular method, I mention it to illustrate that there exists alternative solutions to accomplishing this issue... but first, you have to open to learning those alternatives.

Good luck and best wishes!

  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 10 October 2024 05:22 AM UTC
  2. PowerBuilder
  3. # 3

Hi Suguna,

I think what you want is to execute some code if a user clicked the menu item. So the problem is not to trigger the clicked event (this will PowerBuilder do if the user clickes the item).

As John already wrote: Check how Roland has solved this.

I think you will need to create your own menu item object inherited from Powerbuilder menu object. There you can add code you want to call.

In your code to create a dynamic menu item you have to use your own menu object instead of "menu" for CREATE statement.

HTH,

René

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.