真的需要幫忙~~時間問題ㄛ,微秒?? |
尚未結案
|
cherng32
一般會員 發表:26 回覆:24 積分:10 註冊:2002-09-18 發送簡訊給我 |
|
geniustom
版主 發表:100 回覆:303 積分:260 註冊:2003-01-03 發送簡訊給我 |
cherng32您好...
我最近也在寫類似的東西..所以寫了一個類別來使用...
[code]
TMicroTimer=class //宣告一個可精確到微秒的TIMER類別
Private
StartTime,EndTime,F:int64;
public
NeedTime:real;
Procedure Start();
Procedure Stop();
end;
------------------------以下寫在實作區-----------------------------
Procedure TMicroTimer.Start();
begin
QueryPerformanceFrequency(F);
QueryPerformanceCounter(StartTime);
end; Procedure TMicroTimer.Stop();
begin
QueryPerformanceCounter(ENDTime);
Self.NeedTime:=(ENDTime-StartTime)/(f div 1000)*1000; //微秒
end;
------------------------------------------------------------------- 使用方法...
Timer:=TMicroTimer.create;
Timer.start;
.
.
.
Timer.stop;
showmessage(floattostr(Timer.NeedTime)); ------------------------------------------------------------------
GOOD LUCK
[
|
cherng32
一般會員 發表:26 回覆:24 積分:10 註冊:2002-09-18 發送簡訊給我 |
geniustom您好:
非常謝謝您的回答,但是我再實做的過程中遇到一些問題,所以再請教geniustom一下。
[code]
TMicroTimer=class <--------這一行我是放在type之下,但是會出現"expected':'but'='found"的訊息,將=改成:後會出現更多的錯誤所以想請問一下??謝謝
Private
StartTime,EndTime,F:int64;
public
NeedTime:real;
Procedure Start();
Procedure Stop();
end;
在var的部分是否還要再加上TMicroTimer:NeedTime;這行的宣告呢???謝謝
------------------------以下寫在實作區-----------------------------
Procedure TMicroTimer.Start();
begin
QueryPerformanceFrequency(F);
QueryPerformanceCounter(StartTime);
end; Procedure TMicroTimer.Stop();
begin
QueryPerformanceCounter(ENDTime);
Self.NeedTime:=(ENDTime-StartTime)/(f div 1000)*1000; <------如果我需要更精準的單位,是不是乘以100或是10即可??謝謝
end;
------------------------------------------------------------------- 使用方法...
Timer:=TMicroTimer.create;
Timer.start;
.
.
.
Timer.stop;
showmessage(floattostr(Timer.NeedTime)); 發表人 -
|
geniustom
版主 發表:100 回覆:303 積分:260 註冊:2003-01-03 發送簡訊給我 |
以下是我以前寫過的完整程式...請善加運用...
1..TMicroTimer=class 宣告類別本來就是這樣用了..不用再改錯我的程式了
2..NEEDTIME的單位就是微秒了..您要精確到第幾位..當然可以由您自己決定
//--------------------------------------------------------------------------- unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls,math, TeeProcs, TeEngine, Chart, Series, StdCtrls; type TForm1 = class(TForm) Chart1: TChart; Series2: TLineSeries; Series1: TLineSeries; Label1: TLabel; ComboBox1: TComboBox; Button1: TButton; Label3: TLabel; Label4: TLabel; procedure Button1Click(Sender: TObject); //按下按鈕時的事件 end; TMicroTimer=class //宣告一個可精確到微秒的TIMER類別 Private StartTime,EndTime,F:int64; public NeedTime:real; Procedure Start(); Procedure Stop(); end; var Form1: TForm1; implementation {$R *.dfm} function DivAndCon(x,y:integer):integer; //分而治之法 begin if (x=1) or (x=y) then result:=1 else result:= DivAndCon(x-1,y-1) DivAndCon(x-1,y) end; function DynamicProgram(x,y:integer):integer; //動態規化法 var i,j,n,m:integer; AnsArry:array of array of int64; begin n:=max(x,y); m:=min(x,y); setlength(AnsArry,n 1,n 1); for i:=1 to n do for j:=1 to m do if (i=j) or (j=1) then AnsArry[j,i]:=1 //對角線或X=0時..均為1 else if (j |
cherng32
一般會員 發表:26 回覆:24 積分:10 註冊:2002-09-18 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |