程序中用三个按钮来控件一个label显示计时,一个开始计时,一个停止计时,一个使时间复位,
开始计时按钮代码:
timer1.Enabled:=true;
label7.Caption :=  FormatDateTime('hh:mm:ss', CurrentDate);
停止计时代码:
timer1.Enabled:=false;
复伴按钮代码:
if not timer1.Enabled then
begin
label7.Caption:='00:00:00';
end
else
begin
application.MessageBox('请先停止计时,再进行复位。','提示')
end;
计时器代码:
procedure TChengGoFaBu_F.Timer1Timer(Sender: TObject);
begin
   CurrentDate := IncSecond(CurrentDate);
   label7.Caption:=FormatDateTime('hh:mm:ss', CurrentDate);
   if label7.Caption='00:01:00' then
   begin
   label2.Caption:='时间过去了一分钟';
   beep1;
   end;   if label7.Caption='00:01:30' then
   begin
  label2.Caption:=label2.Caption+#13+'时间到';
   beep2;
   end;
end;问题:
=======================
停止计时后点击复位按钮可以使
label7.Caption='00:00:00'
但是再次点击开始计时按钮后时间又从上次停止时间位开始计时.
============================
我想得到的是:
停止计时后点击复位按钮,时间归为 00:00:00
再次点击开始计时按钮时,时间重新从00:00:00开始计时,要如何做才行呢?请教我,谢谢.

解决方案 »

  1.   

    timer1.Enabled:=false
    timer1.Enabled:=true
    就行了
      

  2.   

    不行的
    timer1.Enabled:=false; 
    再点开始,也就是:timer1.Enabled:=true; 
    并不重新开始计时的,而是从上一次的停止点累加计时,我是想重新开始计时.
      

  3.   

    可以用这段代码试试,一样不能重新开始:
    var
        i:Integer;
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
        i:=i+1;
        Self.Caption :=IntToStr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
        i:=0;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        Timer1.Enabled :=True;
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
        Timer1.Enabled :=False;
    end;
      

  4.   

    动态删除创建timer
    时间可复位
      

  5.   

    我测试的是可以,
     Timer1.Enabled:=false   ;
    Timer1.Enabled:= true ;  
    你有没有搞错哦
      

  6.   

    在点复位按钮的时候,给CurrentDate一个初始值不就得了?
      

  7.   

    雅痞·千年虫说的不错,你把CurrentDate设成一个全局变量,它保存上一次的值啊
    开始计时按钮代码: 
    timer1.Enabled:=true; 
    label7.Caption :=  FormatDateTime( 'hh:mm:ss ', CurrentDate); 
    停止计时代码: 
    timer1.Enabled:=false; 
    复伴按钮代码: 
    if not timer1.Enabled then 
    begin 
    label7.Caption:= '00:00:00 ';
     CurrentDate:=0;   //从新赋初值0end 
    else 
    begin 
    application.MessageBox( '请先停止计时,再进行复位。 ', '提示 ') 
    end;