unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls, ExtCtrls;
type
TAClass = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
FOnTimer: TNotifyEvent;
{ Private declarations }
public
published
Property OnTimer:TNotifyEvent Read FOnTimer Write FOnTimer;
{ Public declarations }
end;
TBClass = class(TAClass)
private
FOnTimer: TNotifyEvent;
procedure OnTimerEvent(Sender: TObject);
procedure DoYourEvent;
public
constructor Create(AOwner: TComponent)
override;
published
Property OnTimer:TNotifyEvent Read FOnTimer Write FOnTimer;//属性重载.
end;
implementation
{$R *.dfm}
procedure TAClass.Timer1Timer(Sender: TObject);
begin
if Assigned(FOnTimer) then
FOnTimer(Self);
end;
{ TBClass }
constructor TBClass.Create(AOwner: TComponent);
begin
inherited;
OnTimer:=OnTimerEvent;//处理父类的OnTimer事件;
end;
procedure TBClass.DoYourEvent;
begin
//想做什么都可以!
end;
procedure TBClass.OnTimerEvent(Sender: TObject);
begin
if Assigned(FOnTimer) then//当父类事件触发时触发自己的事件;
FOnTimer(Self);
DoYourEvent;//再做自己的事!
end;
end.