Make a TActionMainMenuBar on a secondary form work correctly (Views: 28)
Problem/Question/Abstract: On my main form, I have a TActionMainMenuBar with an ActionManager. On my subform, which is placed on the main form, I have a TActionToolbar with a second Actionmanager. Both works fine, but when then second form is active, only the (distinct) shortcuts of the main form are working, the ones of the client form are not. Answer: Solve 1: In order to use a TActionMainMenuBar component on a second form, use the following code in the second form. This overcomes the problem where pressing "ALT" causes the first forms menu bar to appear. procedure TForm2.WMSysCommand(var Message: TWMSysCommand); begin if (Message.CmdType = SC_KEYMENU) then begin Message.Result := SendMessage(ActionMainMenuBar.Handle, Message.Msg, Message.CmdType, Message.Key); if (Message.Result = 0) then inherited; end else inherited; end; Solve 2: Try this code in you application's main form (duplicate it for CMActionUpdate): { ... } procedure CMActionExecute(var Message: TMessage); message CM_ACTIONEXECUTE; { ... } procedure TForm1.CMActionexecute(var Message: TMessage); var bPerformed: Boolean; i: Integer; Form: TCustomForm; begin bPerformed := False; for i := 0 to Pred(Application.ComponentCount) do begin if Application.Components[i] is TCustomForm then begin Form := TCustomForm(Application.Components[i]); if Form.Active then begin Message.Result := Form.Perform(Message.Msg, 0, Message.LParam); {Check the result.} bPerformed := Message.RESULT = S_OK; if bPerformed then begin exit; end; end; end; end; if not bPerformed then begin {If we havent sent the message anywhere then perform the usual} inherited; end; end; |