Jump to content
Pamen

FMX with multiple (child) windows - How to prevent Main Menu and other shortcuts from firing events?

Recommended Posts

Hi, I'm quite new to Delphi (12.2, FMX) so maybe I'm just missing some explanations.

 

I have a FMX application with a main window and main menu (I see the issue on Windows 32/64 bit).

The application shows other child windows and independent non-modal windows.

When a shortcut is pressed in any active window and the shortcut is not directly handled by the child window, main window "intercepts" the shortcut.

The event fires before any private code is executed and main window gets activated, child deactivated.

This makes the whole application unusable, which is a pity after some 100K of lines of code....

Edited by Pamen

Share this post


Link to post

OK, found myself.

Sometimes it is good to wait for someone surely more competent to help and not get an answer 🙂

 

Main form needs a subclasses TMenuItem, which nullifies the event, if the form is not active.

Basically a variation of this, one also needs to typecast some references to FMX.Menus.TMenuItem for this not to throw compiler errors

type
  TMenuItem = class(FMX.Menus.TMenuItem)
  protected
    procedure DialogKey(var Key: Word; Shift: TShiftState); override;
  end;


procedure TMenuItem.DialogKey(var Key: Word; Shift: TShiftState);
begin
  if MainForm.Active = false then exit;       // MainForm must be declared and initialized in TForm.OnCreate or so
  inherited;
end;

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×