J
j5203
Unregistered / Unconfirmed
GUEST, unregistred user!
请问下面这个控件的ONTimer事件为什么不能自动运行?(win98+Delphi6)
unit HrdButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Buttons, QExtCtrls,
QDialogs;
type
THrdButton = class(TSpeedButton)
private
{ Private declarations }
FB: Boolean;
FTimer: TTimer;
FInterval: Integer;
FEnableChange: Boolean;
FColorWidth: Integer;
FColorHeight: Integer;
protected
{ Protected declarations }
procedure Loaded;override;
public
{ Public declarations }
constructor Create(AOwner: Tcomponent);override;
destructor Destroy; override;
procedure TimerTimer(Sender: TObject);
procedure SetInterval(const Value: Integer);
procedure SetEnableChange(const Value: Boolean);
published
{ Published declarations }
property ColorWidth: Integer read FColorWidth write FColorWidth;
property ColorHeight: Integer read FColorHeight write FColorHeight;
property Interval: Integer read FInterval write SetInterval;
property EnableChange: Boolean read FEnableChange write SetEnableChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Ke', [THrdButton]);
end;
{ THrdButton }
procedure THrdButton.TimerTimer(Sender: TObject);
begin
FB := not FB;
if FB then Self.Caption := 'True'
else Self.Caption := 'False';
end;
constructor THrdButton.Create(AOwner: Tcomponent);
begin
inherited;
FInterval := 1000;
FEnableChange := True;
FB := True;
end;
destructor THrdButton.Destroy;
begin
FTimer.Free;
inherited;
end;
procedure THrdButton.Loaded;
begin
inherited;
if not(csDesigning in ComponentState) then
begin
FTimer := TTimer.Create(self);
FTimer.Enabled := True;
FTimer.Interval := 1000;
FTimer.OnTimer := TimerTimer;
end;
end;
procedure THrdButton.SetEnableChange(const Value: Boolean);
begin
FEnableChange := Value;
if Assigned(FTimer) then FTimer.Enabled := Value;
end;
procedure THrdButton.SetInterval(const Value: Integer);
begin
FInterval := Value;
if Assigned(FTimer) then FTimer.Interval := Value;
end;
end.
unit HrdButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Buttons, QExtCtrls,
QDialogs;
type
THrdButton = class(TSpeedButton)
private
{ Private declarations }
FB: Boolean;
FTimer: TTimer;
FInterval: Integer;
FEnableChange: Boolean;
FColorWidth: Integer;
FColorHeight: Integer;
protected
{ Protected declarations }
procedure Loaded;override;
public
{ Public declarations }
constructor Create(AOwner: Tcomponent);override;
destructor Destroy; override;
procedure TimerTimer(Sender: TObject);
procedure SetInterval(const Value: Integer);
procedure SetEnableChange(const Value: Boolean);
published
{ Published declarations }
property ColorWidth: Integer read FColorWidth write FColorWidth;
property ColorHeight: Integer read FColorHeight write FColorHeight;
property Interval: Integer read FInterval write SetInterval;
property EnableChange: Boolean read FEnableChange write SetEnableChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Ke', [THrdButton]);
end;
{ THrdButton }
procedure THrdButton.TimerTimer(Sender: TObject);
begin
FB := not FB;
if FB then Self.Caption := 'True'
else Self.Caption := 'False';
end;
constructor THrdButton.Create(AOwner: Tcomponent);
begin
inherited;
FInterval := 1000;
FEnableChange := True;
FB := True;
end;
destructor THrdButton.Destroy;
begin
FTimer.Free;
inherited;
end;
procedure THrdButton.Loaded;
begin
inherited;
if not(csDesigning in ComponentState) then
begin
FTimer := TTimer.Create(self);
FTimer.Enabled := True;
FTimer.Interval := 1000;
FTimer.OnTimer := TimerTimer;
end;
end;
procedure THrdButton.SetEnableChange(const Value: Boolean);
begin
FEnableChange := Value;
if Assigned(FTimer) then FTimer.Enabled := Value;
end;
procedure THrdButton.SetInterval(const Value: Integer);
begin
FInterval := Value;
if Assigned(FTimer) then FTimer.Interval := Value;
end;
end.