View Single Post
 
Old 12-22-2017, 10:06 PM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

yea this is the real answer to use popup menu

TTPopupMenu = Class(TPopupMenu)
private
FReturnMsg: TControl;
Public
Procedure PopUp(X, Y: Integer; ReturnMsg: TControl = nil); Reintroduce;
procedure MenuReturnClick(Sender: TObject);
//CM_MENUCHANGED message sent to FReturnMsg
end;

{****************************}

procedure TTPopupMenu.MenuReturnClick(Sender: TObject);
begin
inherited;
if ComponentState * [csLoading, csDestroying] = [] then
FReturnMsg.Perform(CM_MENUCHANGED, 0, 0);
DoChange(TMenuItem(Sender), False);
end;

procedure TTPopupMenu.PopUp(X, Y: Integer; ReturnMsg: TControl = nil);
var I: integer;
begin
FReturnMsg := ReturnMsg;
inherited PopUp(X, Y);
If ReturnMsg <> nil then
For I := 0 to Items.Count - 1 do
TMenuItem(Items.Items[I]).OnClick := MenuReturnClick;
end;

And you add in to your controlling object below to pick up the message
procedure CMMENUCHANGED(var Message); message CM_MENUCHANGED;

Last edited by lexd; 12-31-2017 at 05:15 AM.
Reply With Quote