Board index » delphi » Adding TAction to dynamically created TMenuItem

Adding TAction to dynamically created TMenuItem

I have a TMenuItem created at run-time that I am trying to connect to a TAction from an ActionList that I create at design time.  The captions come up blank.  What is the trick to make this work?

Thanks in advance,
KMF

 

Re:Adding TAction to dynamically created TMenuItem


Kurt Frank <kurtfr...@worldnet.att.net> schrieb in im Newsbeitrag:
3a417d26$1_1@dnews...
Quote

> I have a TMenuItem created at run-time that I am trying to connect to a

TAction from an ActionList that I create at design time.  The captions come
up blank.  What is the trick to make this work?

Hi Kurt,
Did you set the caption property of the Action?

Michael

Re:Adding TAction to dynamically created TMenuItem


Quote
"Michael Braendel" <m.braen...@codes.de> wrote:
>Kurt Frank <kurtfr...@worldnet.att.net> schrieb in im Newsbeitrag:
>3a417d26$1_1@dnews...

>> I have a TMenuItem created at run-time that I am trying to connect to a
>TAction from an ActionList that I create at design time.  The captions come
>up blank.  What is the trick to make this work?

>Hi Kurt,
>Did you set the caption property of the Action?

>Michael

Hello Michael,

Yes I did.  Have you been able to  do this?  Maybe a little more detail might help.  

What I am doing is dynamically loading up DLL's in an EXE and getting a TMainMenu from the DLL.  Then I am dynamically creating and inserting TMenuItems into the EXE MainMenu that match the structure of the menu that I get from the DLL.  (I have to do this because you cannot TMainMenu.Merge more than once and I have a half dozen DLLs to merge into the EXE.)

Here is the main loop for this:
for k := 0 to PassedMenu.Items.Count - 1 do
begin
  NewItem := TMenuItem.Create( Menu ) ;
  NewItem.Action := PassedMenu.Items[k].Action ;
  NewItem.GroupIndex := PassedMenu.Items[k].GroupIndex ;
  NewItem.Caption := PassedMenu.Items[k].Caption ;
  NewItem.Hint := PassedMenu.Items[k].Hint ;
  CheckForShortcuts( NewItem ) ;
  // Recursive proc for the submenu items
  AddSubMenus( PassedMenu.Items[k], NewItem ) ;
  // Find proper GroupIndex spot to merge menu with
  t := FindInsertIndex( PassedMenu.Items[k] ) ;
  Menu.Items.Insert( t, NewItem ) ;
end ;

This work around is doing the trick for now but I want to get the TAction working properly.

Thank you for your time,
KMF

Re:Adding TAction to dynamically created TMenuItem


Kurt Frank <kurtfr...@worldnet.att.net> schrieb in im Newsbeitrag:
3a427281$1_2@dnews...

Quote

> Here is the main loop for this:
> for k := 0 to PassedMenu.Items.Count - 1 do
> begin
>   NewItem := TMenuItem.Create( Menu ) ;
>   NewItem.Action := PassedMenu.Items[k].Action ;
>   NewItem.GroupIndex := PassedMenu.Items[k].GroupIndex ;
>   NewItem.Caption := PassedMenu.Items[k].Caption ;
>   NewItem.Hint := PassedMenu.Items[k].Hint ;
>   CheckForShortcuts( NewItem ) ;
>   // Recursive proc for the submenu items
>   AddSubMenus( PassedMenu.Items[k], NewItem ) ;
>   // Find proper GroupIndex spot to merge menu with
>   t := FindInsertIndex( PassedMenu.Items[k] ) ;
>   Menu.Items.Insert( t, NewItem ) ;
> end ;

NewItem.Assign(PassedMenu.Items[k]) will do the same as setting all
properties singly.

But what about the Actionlist? Have you tried to create an ActionList (per
PassedMenu) by yourself first and assign all Actions in the Actionlist of
the dll and after this, creating the menu items?

Best regards,
Michael

Other Threads