Author: Jonas Bilinkevicius
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.
1 2 procedure TForm2.WMSysCommand(varmessage: TWMSysCommand);
3 begin4 if (message.CmdType = SC_KEYMENU) then5 begin6 message.Result := SendMessage(ActionMainMenuBar.Handle, message.Msg,
7 message.CmdType, message.Key);
8 if (message.Result = 0) then9 inherited;
10 end11 else12 inherited;
13 end;
Solve 2:
Try this code in you application's main form (duplicate it for CMActionUpdate):
14 { ... }15 16 procedure CMActionExecute(varmessage: TMessage); message CM_ACTIONEXECUTE;
17 { ... }18 19 procedure TForm1.CMActionexecute(varmessage: TMessage);
20 var21 bPerformed: Boolean;
22 i: Integer;
23 Form: TCustomForm;
24 begin25 bPerformed := False;
26 for i := 0 to Pred(Application.ComponentCount) do27 begin28 if Application.Components[i] is TCustomForm then29 begin30 Form := TCustomForm(Application.Components[i]);
31 if Form.Active then32 begin33 message.Result := Form.Perform(message.Msg, 0, message.LParam);
34 {Check the result.}35 bPerformed := message.RESULT = S_OK;
36 if bPerformed then37 begin38 exit;
39 end;
40 end;
41 end;
42 end;
43 ifnot bPerformed then44 begin45 {If we havent sent the message anywhere then perform the usual}46 inherited;
47 end;
48 end;