Delphi中如何精确到毫秒或纳秒制作启动停止功能的超长尾定时器?

2026-04-10 18:332阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计466个文字,预计阅读时间需要2分钟。

Delphi中如何精确到毫秒或纳秒制作启动/停止功能的超长尾定时器?

在Delphi 7中,我寻找一个以毫秒或纳秒为单位的计时器。我需要通过顺序搜索检查三个ISAM文件的搜索速度。第一个ind文件包含50个字符串,如record_0到record_50。第二个文件从record_0到record_50递增,第三个文件从record_0到record_50递减。

我在Delphi7中寻找一个以毫秒或纳秒为单位的计时器.我必须通过顺序搜索检查三个ISAM文件的速度.第一个ind文件包含50个字符串,如“record_0”到“record_50”.第二个 – “record_0”到“record_500”,第三个 – “record_0”到“record_5000”.我实现了一切,但我不知道如何制作计时器.我正在比较一个字符串与每个ISAM文件中的最后一项.这是我的第一个ind文件的代码:

procedure TForm1.Button1Click(Sender: TObject); var i:integer; var content : String[20]; var indexCounter:integer; var keyword:string; begin //First ISAM file AssignFile(indF1, 'index1.ind'); ReWrite(indF1); Reset(indF1); for i:=0 to 49 do begin content := 'record_'; content := content + IntToStr(i+1); index1.index1 := content; index1.position1 := FileSize(indF1); Seek(indF1, FileSize(indF1)); write(indF1, index1); end; CloseFile(indF1); Label12.Caption := FileSizeStr('index1.ind'); //Sequential search in first ind file Reset(indF1); keyword := 'record_50'; indexCounter := 0; //start timer while not Eof(indF1) do begin Seek(indF1, indexCounter); Read(indF1, Index1); if (keyword = Index1.index1) then begin //stop timer; //Label20 := milliseconds/nanoseconds; //return/break while loop (result := -1; exit;) ??? end; indexCounter := indexCounter + 1; end;

我需要一个过程/函数,以便在调用它时它应该以毫秒或纳秒开始计数,并在找到字符串时停止(它是每个ind文件中的最后一个字符串)并显示遍历所有文件的经过时间.另外我不知道如何打破while循环.提前致谢.

这里描述的TStopWatch类 "delphi-high-performance-timer-tstopwatch"具有所需的所有功能(对于Delphi-7).

它在后来的Delphi版本(Delphi-2010)中实现,作为单元诊断的高级记录.

例:

var sw : TStopWatch; elapsedMilliseconds : cardinal; begin ... sw := TStopWatch.Create() ; try sw.Start; while not Eof(indF1) do begin Seek(indF1, indexCounter); Read(indF1, Index1); if (keyword = Index1.index1) then begin sw.Stop; Label20.Caption := IntToStr(sw.ElapsedMilliseconds); break; // break while loop end; indexCounter := indexCounter + 1; end; ... finally sw.Free; end; end;

要打破while循环,只需要休息;在条件测试中.

Delphi中如何精确到毫秒或纳秒制作启动/停止功能的超长尾定时器?

本文共计466个文字,预计阅读时间需要2分钟。

Delphi中如何精确到毫秒或纳秒制作启动/停止功能的超长尾定时器?

在Delphi 7中,我寻找一个以毫秒或纳秒为单位的计时器。我需要通过顺序搜索检查三个ISAM文件的搜索速度。第一个ind文件包含50个字符串,如record_0到record_50。第二个文件从record_0到record_50递增,第三个文件从record_0到record_50递减。

我在Delphi7中寻找一个以毫秒或纳秒为单位的计时器.我必须通过顺序搜索检查三个ISAM文件的速度.第一个ind文件包含50个字符串,如“record_0”到“record_50”.第二个 – “record_0”到“record_500”,第三个 – “record_0”到“record_5000”.我实现了一切,但我不知道如何制作计时器.我正在比较一个字符串与每个ISAM文件中的最后一项.这是我的第一个ind文件的代码:

procedure TForm1.Button1Click(Sender: TObject); var i:integer; var content : String[20]; var indexCounter:integer; var keyword:string; begin //First ISAM file AssignFile(indF1, 'index1.ind'); ReWrite(indF1); Reset(indF1); for i:=0 to 49 do begin content := 'record_'; content := content + IntToStr(i+1); index1.index1 := content; index1.position1 := FileSize(indF1); Seek(indF1, FileSize(indF1)); write(indF1, index1); end; CloseFile(indF1); Label12.Caption := FileSizeStr('index1.ind'); //Sequential search in first ind file Reset(indF1); keyword := 'record_50'; indexCounter := 0; //start timer while not Eof(indF1) do begin Seek(indF1, indexCounter); Read(indF1, Index1); if (keyword = Index1.index1) then begin //stop timer; //Label20 := milliseconds/nanoseconds; //return/break while loop (result := -1; exit;) ??? end; indexCounter := indexCounter + 1; end;

我需要一个过程/函数,以便在调用它时它应该以毫秒或纳秒开始计数,并在找到字符串时停止(它是每个ind文件中的最后一个字符串)并显示遍历所有文件的经过时间.另外我不知道如何打破while循环.提前致谢.

这里描述的TStopWatch类 "delphi-high-performance-timer-tstopwatch"具有所需的所有功能(对于Delphi-7).

它在后来的Delphi版本(Delphi-2010)中实现,作为单元诊断的高级记录.

例:

var sw : TStopWatch; elapsedMilliseconds : cardinal; begin ... sw := TStopWatch.Create() ; try sw.Start; while not Eof(indF1) do begin Seek(indF1, indexCounter); Read(indF1, Index1); if (keyword = Index1.index1) then begin sw.Stop; Label20.Caption := IntToStr(sw.ElapsedMilliseconds); break; // break while loop end; indexCounter := indexCounter + 1; end; ... finally sw.Free; end; end;

要打破while循环,只需要休息;在条件测试中.

Delphi中如何精确到毫秒或纳秒制作启动/停止功能的超长尾定时器?