Get notified when a TPopupMenu closes?

PeterDelphin
PeterDelphin used Ask the Experts™
on
How can I get notified when a TPopupMenu closes? (Not just by clicking on a menu item but also when closing the popup menu with the Esc key or by clicking elsewhere).

It MUST be a TPopupMenu.

Delphi XE8
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Found the solution here.

Author

Commented:
Will give 500 points to whom can tell me how I can get the popup menu NAME in one of these procedures:

procedure TForm1.CM_MenuClosed(var Msg: TMessage);
begin
  Caption := 'PopMenu closed';
  // Name of the popup menu?
end;

procedure TForm1.CM_ExitMenuLoop(var Msg: TMessage);
begin
  Caption := 'PopMenu exited';
  // Name of the popup menu?
end;

Open in new window

Top Expert 2011

Commented:
type
  TForm1 = class(TForm)
...
  private
    ActivePopup: TPopupMenu;

    procedure CM_MenuClosed(var msg: TMessage) ; message CM_MENU_CLOSED;
    procedure CM_EnterMenuLoop(var msg: TMessage) ; message CM_ENTER_MENU_LOOP;
    procedure CM_ExitMenuLoop(var msg: TMessage) ; message CM_EXIT_MENU_LOOP;
  public
    { Public declarations }
  end;

procedure TForm1.CM_ExitMenuLoop(var msg: TMessage);
begin
  Caption := 'PopMenu exited';

  if not Assigned(ActivePopup) then Exit; {safety}

  showmessage(ActivePopup.Name);

  ActivePopup:= nil;
end;

//All the PopupMenus shall share this OnPopup event
procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  ActivePopup:= (Sender AS TPopupMenu);
end;

Open in new window

Author

Commented:
I want to give you the 500 points. However, there is no button to accept this as part of the solution with 500 points. How can I do this?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial