【问题标题】:Custom Button with Onclick , Hide Onclick Event带有 Onclick 的自定义按钮,隐藏 Onclick 事件
【发布时间】:2019-11-14 13:58:23
【问题描述】:

我创建了一个自定义按钮。我将它与 Grid 连接起来。我已经为 On-click 事件编写了自定义代码。

为了便于理解,简化了下面的代码。

一切正常,如果我单击按钮,则会显示消息。但是因为我在这里运行了更多的代码。如果可能,我想隐藏此按钮的所有事件。即使我实际上使用 TcxButton 作为我的父类,这可能吗?

unit cxGridButton;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, cxButtons,
  cxGridDBTableView, Dialogs;

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

  protected
    { Protected declarations }
  public
    { Public declarations }
     procedure Click; override;
  published
    property DBGridView : TcxGridDBTableView read FGridView write FGridView;
  end;

procedure Register;

implementation

procedure TcxGridButton.Click;
begin
  inherited; // call the inherited Click method.

  ShowMessage('AHA');
end;

procedure Register;
begin
  RegisterComponents('James', [TcxGridButton]);
end;

end.

【问题讨论】:

  • 这是一个很普通也很标准的东西。属性一经发布,就永远存在。正如 Remy 回答的那样,您可以专门针对那些不想在 IDE 中显示的属性。但是你不能阻止用户编写与他们交互的代码。为此,您必须深入挖掘并推出自己的按钮控件。
  • 虽然 'AHA' 很有趣 :)。

标签: delphi events components


【解决方案1】:

设计时,您可以在注册组件时通过调用UnlistPublishedProperty() 向对象检查器隐藏published 属性。

运行时,您无法阻止代码访问public/published 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2019-11-14
    • 2022-01-15
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多