Delphi Pages Forums

Delphi Pages Forums (
-   VCL (
-   -   A popupmenu on Myobject (

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);
if (Source = nil) and (FReturnMsg <> nil) then
FReturnMsg.Perform(CM_MENUCHANGED, 0, 0);

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

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)
FReturnMsg: TControl;
Procedure PopUp(X, Y: Integer; ReturnMsg: TControl = nil); Reintroduce;
procedure MenuReturnClick(Sender: TObject);
//CM_MENUCHANGED message sent to FReturnMsg


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

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

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.