读书人

关于时间的有关问题

发布时间: 2012-03-20 14:01:11 作者: rapoo

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

[解决办法]
用GetTickCount相减就行了:
var
n1: Cardinal;
begin
n1 := GetTickCount;
执行代码
ShowMessage(IntToStr(GetTickCount - n1));
end;

我想几百微秒的时间是测试不出来的,但10毫秒以上应该可以。
time1:=now;
执行代码
time2:=now;
edit1.Text:=floattostr(time2-time1);

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

[解决办法]
unit Unit1;

interface

uses
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.

读书人网 >.NET

热点推荐