【发布时间】: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