Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   VCL (http://www.delphipages.com/forum/forumdisplay.php?f=4)
-   -   A popupmenu on Myobject (http://www.delphipages.com/forum/showthread.php?t=217711)

lexd 12-20-2017 10:09 PM

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

lexd 12-22-2017 10:06 PM

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;


All times are GMT. The time now is 04:38 AM.

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