Delphi實(shí)現(xiàn)毫秒級(jí)別的倒計(jì)時(shí)實(shí)例代碼
本文以實(shí)例簡(jiǎn)述了Delphi實(shí)現(xiàn)毫秒級(jí)別倒計(jì)時(shí)的方法。一般來(lái)說(shuō)可以獲得系統(tǒng)的高性能頻率計(jì)數(shù)器在一毫秒內(nèi)的震動(dòng)次數(shù),如果時(shí)鐘震動(dòng)次數(shù)超過(guò)10毫秒的次數(shù)則刷新edit3的顯示,顯示從開(kāi)始記數(shù)到記數(shù)實(shí)際經(jīng)過(guò)的時(shí)間,具體實(shí)現(xiàn)代碼如下:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, mmsystem; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Button1: TButton; Button2: TButton; Timer1: TTimer; Label1: TLabel; Label2: TLabel; Label3: TLabel; 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的回調(diào)函數(shù) 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 :='開(kāi)始倒計(jì)時(shí)'; button2.caption :='結(jié)束倒計(jì)時(shí)'; 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; //獲得系統(tǒng)的高性能頻率計(jì)數(shù)器在一毫秒內(nèi)的震動(dòng)次數(shù) queryperformancefrequency(lgper); ftemp:=lgper/1000; iten:=trunc(ftemp*10); queryperformancecounter(lgtick1); lgtick2:=lgtick1; spcount:=60; while spcount>0 do begin queryperformancecounter(lgtick2); //如果時(shí)鐘震動(dòng)次數(shù)超過(guò)10毫秒的次數(shù)則刷新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; //顯示從開(kāi)始記數(shù)到記數(shù)實(shí)際經(jīng)過(guò)的時(shí)間 showmessage('實(shí)際經(jīng)過(guò)時(shí)間'+inttostr(acttime2)+'毫秒'); end; end.
- 簡(jiǎn)單易用的倒計(jì)時(shí)js代碼
- VB實(shí)現(xiàn)的倒計(jì)時(shí)類代碼詳解
- Android實(shí)現(xiàn)加載廣告圖片和倒計(jì)時(shí)的開(kāi)屏布局
- jquery實(shí)現(xiàn)倒計(jì)時(shí)代碼分享
- php+js實(shí)現(xiàn)倒計(jì)時(shí)功能
- timespan使用方法詳解
- C#實(shí)現(xiàn)線程安全的簡(jiǎn)易日志記錄方法
- C#與js實(shí)現(xiàn)去除textbox文本框里面重復(fù)記錄的方法
- C#實(shí)現(xiàn)獲取一年中是第幾個(gè)星期的方法
- C#基于TimeSpan實(shí)現(xiàn)倒計(jì)時(shí)效果的方法
相關(guān)文章
Delphi實(shí)現(xiàn)限定軟件使用時(shí)間的方法
這篇文章主要介紹了Delphi實(shí)現(xiàn)限定軟件使用時(shí)間的方法,商業(yè)軟件開(kāi)發(fā)中非常實(shí)用的功能,需要的朋友可以參考下2014-07-07Delphi用TActionList實(shí)現(xiàn)下載文件的方法
這篇文章主要介紹了Delphi用TActionList實(shí)現(xiàn)下載文件的方法,需要的朋友可以參考下2014-07-07DELPHI7.0 獲取硬盤(pán)、CPU、網(wǎng)卡序列號(hào)的代碼
DELPHI7.0 獲取硬盤(pán)、CPU、網(wǎng)卡序列號(hào)的代碼,使用DELPHI編程的朋友可以參考下。2011-09-09為什么繼續(xù)選擇DELPHI(即將逝去的Delphi前景在何方)
已經(jīng)鉆DELPHI很深了,當(dāng)然現(xiàn)在DELPHI是過(guò)了最輝煌的時(shí)代。但為什么要繼續(xù)下去,而不轉(zhuǎn)向其它的?這是不是死腦筋2018-02-02在Delphi實(shí)現(xiàn)在數(shù)據(jù)庫(kù)中存取圖像的圖文演示無(wú)錯(cuò)
最近打算學(xué)習(xí)Delphi實(shí)現(xiàn)在數(shù)據(jù)庫(kù)中存取圖像,網(wǎng)上的好多Delphi實(shí)現(xiàn)在數(shù)據(jù)庫(kù)中存取圖像都是錯(cuò)誤的,所以我把圖片給弄好了。2008-01-01Delphi創(chuàng)建開(kāi)機(jī)啟動(dòng)項(xiàng)的方法示例
這篇文章主要介紹了Delphi創(chuàng)建開(kāi)機(jī)啟動(dòng)項(xiàng)的方法,很有實(shí)用價(jià)值,需要的朋友可以參考下2014-07-07