Delphi:PopupMenu 在我的组件中不起作用

发布于 2024-11-01 07:51:28 字数 774 浏览 1 评论 0原文

英文翻译(已经有一段时间了,所以可能不完全准确;使用谷歌翻译来翻译我遇到问题的部分):

我正在 Delphi 中开发一个可视化组件(它不是标准的 Delphi 组件),它拥有一个名为 < 的属性代码>弹出菜单。我将组件中的属性 PopupMenu 与 PopupMenu 关联起来,但是当我单击[鼠标]右键时,我什么也没看到。

我还尝试用此代码强制它显示:

x:= Mouse.CursorPos.X; 
y:= Mouse.CursorPos.Y; 
// //showmessage(inttostr(x)) PopupMenu1.Popup(x,y);

我有两个问题:

你如何知道鼠标右键单击处于活动状态?你们中有人遇到过此类问题吗?谢谢您的回答。

谢谢

编辑

这是我用来执行PopupMenu1:过程的过程

TForm6.GeckoBrowser1DOMMouseDown(Sender: TObject; Key: Word); 
var x,y:integer; 
begin 
  if key=VK_RBUTTON then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y; 
    //showmessage(inttostr(x)) PopupMenu1.Popup(x,y); 
  end; 
end;

English Translation (been a while, so may not be entirely accurate; used google translate for the parts I had trouble with):

I'm working on a Visual Component in Delphi (it's not a standard Delphi component) which possesses a property called PopupMenu. I associated the property PopupMenu in the component with the PopupMenu, but when I click the right button [of the mouse], I see nothing.

I also tried to force it to display with this code:

x:= Mouse.CursorPos.X; 
y:= Mouse.CursorPos.Y; 
// //showmessage(inttostr(x)) PopupMenu1.Popup(x,y);

I have two questions:

How do you know that the right click of the mouse is active? Have any of you encountered this type of problem? Thank you for your answers.

Thanks

EDIT

Here is the procedure that I'm using to execute the PopupMenu1: procedure

TForm6.GeckoBrowser1DOMMouseDown(Sender: TObject; Key: Word); 
var x,y:integer; 
begin 
  if key=VK_RBUTTON then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y; 
    //showmessage(inttostr(x)) PopupMenu1.Popup(x,y); 
  end; 
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不及他 2024-11-08 07:51:29

这永远不会起作用。您不能将表单中的代码与组件代码混合。

我建议这样:

interface

type
  TGeckoBrowser = class(....
private
  FPopupmenu: TPopupMenu;
protected
  ...
  procedure MouseUp(Sender: TObject; Key: Word); override;
  ...
published
  property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
end;

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  inherited;
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end; {if}
end;  

或者如果您不希望 OnMouseUp 在出现弹出菜单时触发,请执行以下操作:

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end {if}
  else inherited;
end;  

看到区别了吗? Popupmenu 现在是组件的一部分(无论如何都是良好链接的部分),而不是恰好位于同一表单上的东西。

This will never work. You cannot mix code in a form with the component code.

I would suggest something like this:

interface

type
  TGeckoBrowser = class(....
private
  FPopupmenu: TPopupMenu;
protected
  ...
  procedure MouseUp(Sender: TObject; Key: Word); override;
  ...
published
  property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
end;

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  inherited;
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end; {if}
end;  

or if you do not want the OnMouseUp to fire when a popup menu appears do:

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end {if}
  else inherited;
end;  

See the difference? Popupmenu is now a part (well linked part anyway) of your component and not something that just happens to be on the same form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文