由于按钮是组件私有的,您只需将事件处理程序附加到它,即
THidePanel = class(TPanel)
...
private
procedure H_ActivateButtonClick(Sender: TObject);
...
end;
constructor THidePanel.Create(aOwner: TComponent);
begin
inherited;
...
FActivateButton := TButton.Create(Self);
FActivateButton.Parent := Self;
FActivateButton.OnClick:= H_ActivateButtonClick;
end
procedure THidePanel.H_ActivateButtonClick(Sender: TObject)
begin
// button is clicked!
end
如果您还需要向组件的最终用户提供事件,那么您需要添加一个TNotifyEvent
属性并从您的内部处理程序中调用它,即
THidePanel = class(TPanel)
private
FOnActivateBtnClick: TNotifyEvent;
...
published
property OnActivateButtonClick: TNotifyEvent read FOnActivateBtnClick write FOnActivateBtnClick;
end;
procedure THidePanel.H_ActivateButtonClick(Sender: TObject)
begin
// button is clicked!
...
// fire the end user event
if(Assigned(FOnActivateBtnClick))then FOnActivateBtnClick(Self);
end