Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of PeterDelphin
PeterDelphin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterDelphin
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

Avatar of 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

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?