unit Unit5;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TTest =
class(TComponent)
private
FTimer: TTimer;
function GetOnTimer: TNotifyEvent;
procedure SetOnTimer(
const Value: TNotifyEvent);
function GetEnabled: Boolean;
procedure SetEnabled(
const Value: Boolean);
public
constructor Create(AOwner: TComponent);
override;
published
property Enabled: Boolean
read GetEnabled
write SetEnabled;
property OnTimer: TNotifyEvent
read GetOnTimer
write SetOnTimer;
end;
TfrmKomponentenTest =
class(TForm)
lblTimerFired: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
FTest: TTest;
FZahl: integer;
procedure DoOnTimer(Sender: TObject);
public
{ Public-Deklarationen }
end;
var
frmKomponentenTest: TfrmKomponentenTest;
implementation
{$R *.dfm}
{ TTest }
constructor TTest.Create(AOwner: TComponent);
begin
inherited;
FTimer := TTimer.Create(self);
FTimer.Enabled := false;
end;
function TTest.GetEnabled: Boolean;
begin
Result := FTimer.Enabled;
end;
function TTest.GetOnTimer: TNotifyEvent;
begin
Result := FTimer.OnTimer;
end;
procedure TTest.SetEnabled(
const Value: Boolean);
begin
FTimer.Enabled := Value;
end;
procedure TTest.SetOnTimer(
const Value: TNotifyEvent);
begin
FTimer.OnTimer := Value;
end;
{ TfrmKomponentenTest }
procedure TfrmKomponentenTest.DoOnTimer(Sender: TObject);
begin
inc(FZahl);
lblTimerFired.Caption := IntToStr(FZahl);
end;
procedure TfrmKomponentenTest.FormCreate(Sender: TObject);
begin
FTest := TTest.Create(self);
FTest.OnTimer := DoOnTimer;
FTest.Enabled := true;
end;
end.