简体   繁体   English

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

[英]Delphi: PopupMenu doesn't work in my component

English Translation (been a while, so may not be entirely accurate; used google translate for the parts I had trouble with): 英文翻译(可能需要一段时间,所以可能并不完全准确;对于我遇到问题的部分,请使用google翻译):

I'm working on a Visual Component in Delphi (it's not a standard Delphi component) which possesses a property called PopupMenu . 我正在使用Delphi中的Visual Component(它不是标准的Delphi组件)进行开发,该组件具有一个称为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. 我将组件中的属性PopupMenu与PopupMenu关联起来,但是当我单击鼠标的右键时,什么都看不到。

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 这是我用来执行PopupMenu1:过程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;

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: 或者,如果您不希望在出现弹出菜单时触发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;  

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. Popupmenu现在是组件的一部分(无论如何都很好地链接在一起),而不是恰好处于同一形式的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM