请问怎么样实时检测程序运行的时间?也就是说我设置一个程序的运行时间,到这个时间程序就强制退出?

解决方案 »

  1.   

    用GetTickCount相减就行了:
    var
      n1: Cardinal;
    begin
      n1 := GetTickCount;
      执行代码
      ShowMessage(IntToStr(GetTickCount - n1));
    end;我想几百微秒的时间是测试不出来的,但10毫秒以上应该可以。
      time1:=now;
      执行代码
      time2:=now;
      edit1.Text:=floattostr(time2-time1);
      

  2.   

    最简单的
    用个TIMER控件 interval属性设置你想要关闭的时间(ms) 
    在工程代码写上Application.Terminate
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Application.Terminate;
    end;end.
      

  4.   

    这种最简单的方式我不可以用,还是用
    yintao1021() 
    提出的第一种方式吧