Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 自定义按钮,单击弹出菜单_Delphi_Events_Components - Fatal编程技术网

Delphi 自定义按钮,单击弹出菜单

Delphi 自定义按钮,单击弹出菜单,delphi,events,components,Delphi,Events,Components,因此,我基于cxButton创建了一个自定义按钮。我希望在单击此按钮时显示弹出菜单。但是由于某种原因,弹出菜单没有出现。 我连一个错误都没有,我不知道为什么 type TcxGridButton = class(TcxButton) private FGridView : TcxGridDBTableView; FPopup : TPopupMenu; procedure AutoSize(Sender : TObject); procedure Cle

因此,我基于cxButton创建了一个自定义按钮。我希望在单击此按钮时显示弹出菜单。但是由于某种原因,弹出菜单没有出现。 我连一个错误都没有,我不知道为什么

type
  TcxGridButton = class(TcxButton)
  private
    FGridView : TcxGridDBTableView;
    FPopup : TPopupMenu;

    procedure AutoSize(Sender : TObject);
    procedure ClearFilter(Sender : TObject);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;

    procedure Click; override;
  published
    property GridView : TcxGridDBTableView read FGridView write FGridView;
  end;
这是我创建弹出菜单的部分

constructor TcxGridButton.Create(AOwner: TComponent);
var Item : TMenuItem;
    P : TPoint;
begin
  inherited;

  Text:='Options';

  FPopup := TPopupMenu.Create(Self);

  Item := TMenuItem.Create(FPopup);
  Item.Caption:='Nach Excel exportieren';

  Item := TMenuItem.Create(FPopup);
  Item.Caption:='Automatische Größenanpassung';
  Item.OnClick:=AutoSize;

  Item := TMenuItem.Create(FPopup);
  Item.Caption:='Filter löschen';
  Item.OnClick:=ClearFilter;
end;
现在,当我把这个按钮放在表单上时,它会立即显示文本选项,这样构造函数看起来运行正常

但是当我点击这个按钮时,我得到了点击,Self.ToString并完成了。 但是弹出菜单永远不会弹出。我犯了什么错

procedure TcxGridButton.Click;

begin
  inherited; // call the inherited Click method.

  ShowMessage('CLICK');

  if not Assigned(FGridView) then Exit;

  ShowMessage(Self.ToString);


  FPopup.Popup(0,0);


  ShowMessage('DONE');

end;

答案很简单-您忘记将项目添加到弹出菜单:

{ after creating each item }
FPopup.Items.Add(Item);

如果您没有绑定到
TCxButton
,您可以使用标准VCL按钮,该按钮通过设置为
bsSplitButton
的属性和属性提供您试图实现的功能。否则,您至少可以学习VCL的
TCustomButton
源代码,作为您自己实现的灵感。

答案非常简单-您忘记将项目添加到弹出菜单:

{ after creating each item }
FPopup.Items.Add(Item);

如果您没有绑定到
TCxButton
,您可以使用标准VCL按钮,该按钮通过设置为
bsSplitButton
的属性和属性提供您试图实现的功能。否则,您至少可以学习VCL的
TCustomButton
源代码,作为您自己实现的灵感。

谢谢您,难以置信的是我监督了这一点:)谢谢-谢谢-谢谢!我使用了cxButton,因为我用cxGrid连接了这个组件,在那里我做了一些我经常做的事情。我刚刚意识到我可以为它创建一个组件,而不是每次都为三个按钮编写代码谢谢,难以置信的是我监督了这个:)谢谢-谢谢-谢谢!我使用了cxButton,因为我用cxGrid连接了这个组件,在那里我做了一些我经常做的事情。我刚刚意识到我可以为此创建一个组件,而不是每次为三个按钮编写代码