procedure TForm1.Timer1Timer(Sender: TObject);
begins:=s-1;
maskedit1.Text:=format('%d:%d:%d',[h,n,s]);if s=0 then
begin
n:=n-1;
s:=60;
end; if (h=0) and (n=0) and (s=0) then
begin
timer1.Enabled:=false;
showmessage('预定时间结束!'); end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
s:=60;n:=strtoint(edit1.Text)-1;
h:=n div 60;
Timer1.Enabled:=true;end;end.
以上是我的代码 但是 为什么我的这个倒计时到时间了 不会停 还会往负数走求高手指点!!!!
begins:=s-1;
maskedit1.Text:=format('%d:%d:%d',[h,n,s]);if s=0 then
begin
n:=n-1;
s:=60;
end; if (h=0) and (n=0) and (s=0) then
begin
timer1.Enabled:=false;
showmessage('预定时间结束!'); end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
s:=60;n:=strtoint(edit1.Text)-1;
h:=n div 60;
Timer1.Enabled:=true;end;end.
以上是我的代码 但是 为什么我的这个倒计时到时间了 不会停 还会往负数走求高手指点!!!!
//这个判断有问题,因为之前的判断把s赋值成了60。
之前的判断修改为
if s=0 and n<>0 then
begin
n:=n-1;
s:=60;
end;
begin
n:=n-1;
s:=60;
end;这个条件不正确,要考虑到当h和n都为0的情况下不执行应该为 if (s=0) and (h<>0 or n<>0) then
begin
s:=60;
n:=strtoint(edit1.Text)-1;
h:=n div 60;
n:=n mod 60; //修正分钟显示
Timer1.Enabled:=true;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
s:=s-1;
maskedit1.Text:=format('%d:%d:%d',[h,n,s]); if (s=0)and(n>0) then //修改重置 秒 条件
begin
n:=n-1;
s:=60;
end; if (h=0) and (n=0) and (s=0) then
begin
timer1.Enabled:=false;
showmessage('预定时间结束!');
end;
end;