本人菜鸟一只,望各位高手,前辈写一个关于计数器的代码!
比如,我点击button开始计时,当再次点击button时停止计时,并且将此期间的所用时间返回到edit1里

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Timer1: TTimer;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      i:integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin
      if not timer1.Enabled then
      begin
        i := 0;
        timer1.Enabled := true;
      end
      else
      begin
        edit1.Text := inttostr(i);
        timer1.Enabled :=false;
      end;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      i := i+1;
    end;end.