用delphi做倒计时软件 20
我刚才用timer做了一个倒计时软件,但测试发现无论怎么改,每分钟总是差几秒.以下是代码.我设置的interval是100.(我还试过设置的interval为90)为了方...
我刚才用timer做了一个倒计时软件,但测试发现无论怎么改,每分钟总是差几秒.
以下是代码.
我设置的interval是100.(我还试过设置的interval为90)
为了方便用系统时间对比测试,我做成了顺计时.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
Label4: TLabel;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c :Integer;
aa:Integer=0;
bb:Integer=0;
cc:Integer=0;
dd :Integer=0;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if aa<8 then //我试过aa<9或aa<10都不行
begin
aa:=aa+1;
end
else if bb < 59 then
begin
bb:=bb+1;
aa:=0;
end
else if cc<a then
begin
cc:=cc+1;
bb:=0;
end
else
exit;
label4.Caption:=floattostr(cc)+':'+floattostr(bb)+':'+floattostr(aa)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
a:=strtoint(Edit1.Text);
Timer1.Enabled:=true;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Timer1.Enabled:=false;
aa:=0;
bb:=0;
cc:=0;
label4.Caption:=floattostr(cc)+':'+floattostr(bb)+':'+floattostr(aa)
end;
end. 展开
以下是代码.
我设置的interval是100.(我还试过设置的interval为90)
为了方便用系统时间对比测试,我做成了顺计时.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
Label4: TLabel;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c :Integer;
aa:Integer=0;
bb:Integer=0;
cc:Integer=0;
dd :Integer=0;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if aa<8 then //我试过aa<9或aa<10都不行
begin
aa:=aa+1;
end
else if bb < 59 then
begin
bb:=bb+1;
aa:=0;
end
else if cc<a then
begin
cc:=cc+1;
bb:=0;
end
else
exit;
label4.Caption:=floattostr(cc)+':'+floattostr(bb)+':'+floattostr(aa)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
a:=strtoint(Edit1.Text);
Timer1.Enabled:=true;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Timer1.Enabled:=false;
aa:=0;
bb:=0;
cc:=0;
label4.Caption:=floattostr(cc)+':'+floattostr(bb)+':'+floattostr(aa)
end;
end. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询