Picture the scenario where the user just taps the Alt key.
Normal Windows apps highlight the menu on the current form, or do nothing if they don't have a menu. The code that handles CMAppSysCommand propagates CM_APPSYSCOMMAND to the Application, which gets handled by the MainForm.
I cannot see any reason for doing this.
It doesn't do anything if the main form is disabled (which is the case if something is shown modally from it)
If the main form is enabled: it pops the main form forward and highlights the menu.
This is awkward, and I can't imagine that can ever be an intended behavior.
The fix
Stop doing that.
procedure TCustomForm.CMAppSysCommand(var Message: TMessage);
{$IF NOT DEFINED(CLR)}
type
PWMSysCommand = ^TWMSysCommand;
{$ENDIF}
begin
Message.Result := 0;
if (csDesigning in ComponentState) or (FormStyle = fsMDIChild) or
(Menu = nil) or Menu.AutoMerge then
{$IF DEFINED(CLR)}
with TWMSysCommand.Create(Message) do
{$ELSE}
with PWMSysCommand(Message.lParam)^ do
{$ENDIF}
begin
{
Picture the scenario where the user just taps the Alt key.
Normal Windows apps highlight the menu on the current form, or do nothing if they don't have a menu.
The code that handles **CMAppSysCommand** propagates `CM_APPSYSCOMMAND` to the **Application**, which gets handled by the **MainForm**.
I cannot see any reason for doing this.
- It doesn't do anything if the main form is disabled (which is the case if something is shown modally from it)
- If the main form is enabled: it pops the main form forward and highlights the menu.
This is awkward, and I can't imagine that can ever be an intended behavior.
Comment out the the propagation to the main form, and act as though we handled the message ourselves
}
// SendCancelMode(nil);
// if SendAppMessage(CM_APPSYSCOMMAND, CmdType, Key) <> 0 then
Message.Result := 1;
end;
end;
Tested
Delphi XE6: Fails Delphi 10.3: Fails Delphi 10.4: Fails
Picture the scenario where the user just taps the Alt key.
Normal Windows apps highlight the menu on the current form, or do nothing if they don't have a menu. The code that handles CMAppSysCommand propagates
CM_APPSYSCOMMAND
to the Application, which gets handled by the MainForm.I cannot see any reason for doing this.
This is awkward, and I can't imagine that can ever be an intended behavior.
The fix
Stop doing that.