Dynamic Action Menu Items on the Fly
At the CodeCamp session of the EKON a visitor of the conference came up to me asking me, how to populate a totaly empty action main menu with menus and sub menus. Most of you have seen the action manager components and used them, however usually only, or at least mostly using the visual tools of the IDE.
I guess we were sitting there about one or two hours (off and on) trying to solve their problem. We even asked quiet a few more conference attendees if they would know a solution to the problem. All in all, I guess, we were 8 people trying to figure that one out - to no success. So later, I wrote one of the people I really know they love the action components and asked for his advice and he basically wrote back, that even he does not know a solution to this problem. Btw, using various search engines didn't offer any success either.
Now, two days later, sitting in a session of Marco Cantù on Web 2.0 stuff, it hit me straight into the face. And the solution is actually rather simple. If you simply drop an action main menu on your form, you'll have to add a new action bar to your action manager and connect this with the menu. Now you can go ahead and add menu items to it. To create sub menus within a menu, you have to create a new TContainedAction and assign that to the menu item. Further, you have to set the caption of the TActionMenuItem separately. I have added a sample to Borlands CodeCentral for you to download. It does everything programatically and should be easily adaptable for your purposes.
CodeCentral: download for registered members (Delphi 2006 and C++Builder 2006)
I guess we were sitting there about one or two hours (off and on) trying to solve their problem. We even asked quiet a few more conference attendees if they would know a solution to the problem. All in all, I guess, we were 8 people trying to figure that one out - to no success. So later, I wrote one of the people I really know they love the action components and asked for his advice and he basically wrote back, that even he does not know a solution to this problem. Btw, using various search engines didn't offer any success either.
Now, two days later, sitting in a session of Marco Cantù on Web 2.0 stuff, it hit me straight into the face. And the solution is actually rather simple. If you simply drop an action main menu on your form, you'll have to add a new action bar to your action manager and connect this with the menu. Now you can go ahead and add menu items to it. To create sub menus within a menu, you have to create a new TContainedAction and assign that to the menu item. Further, you have to set the caption of the TActionMenuItem separately. I have added a sample to Borlands CodeCentral for you to download. It does everything programatically and should be easily adaptable for your purposes.
CodeCentral: download for registered members (Delphi 2006 and C++Builder 2006)
0 Comments:
Post a Comment
<< Home