Avatar of PeterDelphin
PeterDelphin
 asked on

Get notified when a TPopupMenu closes?

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
DelphiPascal

Avatar of undefined
Last Comment
PeterDelphin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PeterDelphin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PeterDelphin

ASKER
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

jimyX

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

PeterDelphin

ASKER
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?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck