Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-20-2017, 10:09 PM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default A popupmenu on Myobject

I have a popup menu connected with code out of TToolBar (ComCtrls) line 2954
as I trace through the code its extremely complex to say the lest.

I feel like making a descendant menu and override the popup method
with its screen location add a Return: TControl to the popup Method as a
sow you type PopUp(x, y, Self); to activate the menu.
The return simply call a perform(CM_MENUCHANGED)
It still allows the menu to operate as a standard Menu but its beyond me why Delphi has to be so difficult with its code.

{ TTMenu }

procedure TTPopupMenu.MenuChanged(Sender: TObject; Source: TMenuItem;
Rebuild: Boolean);
begin
inherited;
if (Source = nil) and (FReturnMsg <> nil) then
FReturnMsg.Perform(CM_MENUCHANGED, 0, 0);
end;

procedure TTPopupMenu.PopUpMsg(X, Y: Integer; ReturnMsg: TControl);
begin
FReturnMsg := ReturnMsg;
inherited PopUp(X, Y);
end;

Does any one have a better idea

Last edited by lexd; 12-21-2017 at 02:53 AM.
Reply With Quote
  #2  
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:29 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.