怎么样给我的程序计算出时间并显示出来?
比如说一个过程需要多少秒可以执行完成,
我用timer控件,搞不出来,有会的给说一声,谢谢~
在线等待,解决给分!

解决方案 »

  1.   

    unit Unit1; interface uses  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  StdCtrls, ExtCtrls,mmSystem; type  TForm1 = class(TForm)    Edit1: TEdit;    Edit2: TEdit;    Edit3: TEdit;    Button1: TButton;    Button2: TButton;    Timer1: TTimer;    procedure FormCreate(Sender: TObject);    procedure Button1Click(Sender: TObject);    procedure Timer1Timer(Sender: TObject);    procedure Button2Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; var  Form1: TForm1;  actTime1,actTime2:Cardinal;  smmCount,sTimerCount,sPCount:Single;  hTimeID:Integer;  iTen:Integer;  proTimeCallBack:TFNTimeCallBack; procedure TimeProc(uTimerID, uMessage: UINT;     dwUser, dw1, dw2: DWORD) stdcall;procedure proEndCount;implementation {$R *.DFM}//timeSetEvent的回调函数procedure proEndCount;begin  actTime2:=GetTickCount-actTime1;  Form1.Button2.Enabled :=False;  Form1.Button1.Enabled :=TRue;  Form1.Timer1.Enabled :=False;  smmCount:=60;  sTimerCount:=60;  spCount:=-1;   timeKillEvent(hTimeID);end; procedure TimeProc(uTimerID, uMessage: UINT;    dwUser, dw1, dw2: DWORD) stdcall;begin  Form1.Edit2.Text:=FloatToStr(smmCount);  smmCount:=smmCount-0.01;end; procedure TForm1.FormCreate(Sender: TObject);begin  Button1.Caption :=´开始倒计时´;  Button2.Caption :=´结束倒计时´;  Button2.Enabled :=False;  Button1.Enabled :=True;  Timer1.Enabled :=False;  smmCount:=60;  sTimerCount:=60;  sPCount:=60;end; procedure TForm1.Button1Click(Sender: TObject);var  lgTick1,lgTick2,lgPer:TLargeInteger;  fTemp:Single;begin  Button2.Enabled :=True;  Button1.Enabled :=False;  Timer1.Enabled :=True;  Timer1.Interval :=10;  proTimeCallback:=TimeProc;  hTimeID:=timeSetEvent(10,0,proTimeCallback,1,1);  actTime1:=GetTickCount;   //获得系统的高性能频率计数器在一毫秒内的震动次数  QueryPerformanceFrequency(lgPer);  fTemp:=lgPer/1000;  iTen:=Trunc(fTemp*10);  QueryPerformanceCounter(lgTick1);  lgTick2:=lgTick1;  sPCount:=60;  while sPCount>0 do begin    QueryPerformanceCounter(lgTick2);    //如果时钟震动次数超过10毫秒的次数则刷新Edit3的显示    If lgTick2 - lgTick1 > iTen Then begin            lgTick1 := lgTick2;            sPCount := sPCount - 0.01;            Edit3.Text := FloatToStr(sPCount);            Application.ProcessMessages;    end;  end;end; procedure TForm1.Timer1Timer(Sender: TObject);begin  Edit1.Text := FloatToStr(sTimerCount);  sTimerCount:=sTimerCount-0.01;end;procedure TForm1.Button2Click(Sender: TObject);begin  proEndCount;  //显示从开始记数到记数实际经过的时间  ShowMessage(´实际经过时间´+IntToStr(actTime2)+´毫秒´);end;end.
      

  2.   

    timer1.enable:=true;
    application.ProcessMessages;
    .....
    timer1.enable:=false;
      

  3.   

    在函数开始和结束的地方加上gettickcount
      

  4.   

    procedure aaa;
    var
      esc: integer;
    begin
      esc := gettickcount;
      ......
      esc := gettickcount - esc;
      //esc包含了过程运行的毫秒数
    end;
      

  5.   

    hongqi162(失踪的月亮) ( ) 
    用你的方法怎么没有进入timer1timer事件
      

  6.   

    procedure Tfrm.ChangeClick(Sender: TObject);
    begin
      I := 0;
      Timer1.Enabled := True;
      Application.ProcessMessages;
      //Timer1Time;  Inysdak1;       //其中一个过程
      ChangeData;     //其中另一个过程  Timer1.Enabled := False;
    end;procedure Tfrm.Timer1Timer(Sender: TObject);
    begin
      Inc(I);
      //Application.ProcessMessages;
      Label1.Caption := Format('%d', [I]);
    end;
    label1不显示时间的变化
    看看吧,大哥们,怎么解决?
      

  7.   

    让时间一秒一秒显示?
    FormCreate事件
    Label1 := FormatDateTime('yyyy-mm-dd hh:mm:nn',now);//StartTime
    Label2 := FormatDateTime('yyyy-mm-dd hh:mm:nn',now);//NowTime
    Label3 := FormatDateTime('hh:mm:ss',StrToDateTime(Label2.Caption)-StrToDateTime(Label1.Caption);//intervalTimer事件
    Label2 := FormatDateTime('yyyy-mm-dd hh:mm:nn',now);//NowTime
    Label3 := FormatDateTime('hh:mm:ss',StrToDateTime(Label2.Caption)-StrToDateTime(Label1.Caption);//interval