怎样做一个简单的计时器?可以控制开始和结束,如从20到0。

解决方案 »

  1.   

    var
      Form1: TForm1;
      i:integer=20;
    implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    begin
       i:=i-1;
       edit1.text:=inttostr(i);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
         timer1.Enabled:=true; //开始
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
        timer1.Enabled:=false; //停止
    end;
      

  2.   

    Timer就搞定了_____________________
    http://lysoft.7u7.net
      

  3.   

    保存一个全局变量先
    var
      i:integer...........然后在timer事件中
    begin
      i:=i+1;
    然后就可以使用这个i了
      
    end;
      

  4.   

    用Timer记时是不精确的,只能用来作一些要求不严格的事情。
      

  5.   

    用一个thread
    这是一个最最简陋的定时器,不过可以精确到毫秒
    ------------------------------
    unit Unit1;interfaceuses
      windows,Classes;type
      TimerThread = class(TThread)
      private
        { Private declarations }
        dBegin,dEnd : Dword;
      protected
        procedure Execute; override;
      public
          FCanClose : Boolean;
      end;implementation{ Important: Methods and properties of objects in visual components can only be
      used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TimerThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TimerThread }procedure TimerThread.Execute;
    begin
      { Place thread code here }
      dBegin := GetTickCount;
      while not FCanClose do
      begin
        dEnd := GetTickCount;
        if  dEnd-dBegin>=1000 then
        begin
           //在这里写代码       dBegin := GetTickCount;
        end;
      end;
    end;end.