線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3032
推到 Plurk!
推到 Facebook!

Sleep()函數?

尚未結案
ohsula
一般會員


發表:12
回覆:17
積分:5
註冊:2004-03-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-20 23:43:03 IP:218.169.xxx.xxx 未訂閱
各位大大: 我使用BCB內的Sleep()函數,為達到延遲一段時間的效果,但程式中視窗內的元件都不能控制了,必須等到Sleep()函數執行完,是否有辦法可解決?亦或必須利用別的辦法來達到delay的效果? 例如: 我希望程式執行中,若觸發另一Button事件可中斷執式執行,但主程式中因用到sleep()函數,而使執行當中利用滑鼠去觸發另一事件。 Auston Huang
------
Auston Huang
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-20 23:55:33 IP:61.221.xxx.xxx 未訂閱
引言: 各位大大: 我使用BCB內的Sleep()函數,為達到延遲一段時間的效果,但程式中視窗內的元件都不能控制了,必須等到Sleep()函數執行完,是否有辦法可解決?亦或必須利用別的辦法來達到delay的效果? 例如: 我希望程式執行中,若觸發另一Button事件可中斷執式執行,但主程式中因用到sleep()函數,而使執行當中利用滑鼠去觸發另一事件。 Auston Huang
ohsula 你好:
舉一個例子,如果你想要 delay 5 秒,不要這樣子寫
   Sleep(5000);
改成這樣子寫
   >>    < src="http://delphi.ktop.com.tw/loadfile.php?TOPICID=10003806&CC=223734"> -- Enjoy Researching & Developing --
        
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
HomeSound
中階會員


發表:44
回覆:178
積分:94
註冊:2002-08-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-03-21 02:29:28 IP:61.30.xxx.xxx 未訂閱
#include  //要引入
void __fastcall Tform1::Delay(unsigned int mSec)
{
 unsigned int StartTime,CheckTime;
 StartTime=timeGetTime();
 do
   { CheckTime=timeGetTime();
     Application->ProcessMessages();
   }
 while ((CheckTime-StartTime)<=mSec);
}
此函數跟RaynorPao大佬是類似的原理. --==多看.多學.多聽==--
------
--==多看.多學.多聽==--
ohsula
一般會員


發表:12
回覆:17
積分:5
註冊:2004-03-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-03-21 19:06:33 IP:218.169.xxx.xxx 未訂閱
各位大佬好:  採用你們的建議,寫一個delay的副函數,當主程式執行時testclick按下後,視窗內的元件已經可以控制,但為什麼程式執行時當我按下endclick,程式不會停止執呢?以下是我的程式碼:  滿長的,但最主要是endClick事件,是不是不應該放在endClick內?因為我希望當程式執行,能按下endClick來停止程式執行。  是因為testClick事件程序尚未執行完,就算按下endClick鍵,也無法終止執行嗎?請問各位大大那我應該怎麼做呢?    //---------------------------------------------------------------------------    #include  #pragma hdrstop #include #include <math.h> #include #include "u41007T0_1u.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; float vol,freq; void delay(double s); void test_1(int *ok); void test_2(int *ok); void test_3(int *ok); void test_4(int *ok); void test_5(int *ok); void test_6(int *ok); void test_7(int *ok); void test_8(int *ok); void test_9(int *ok); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Timer1->Enabled=true; Timer1->Interval=1000; } //--------------------------------------------------------------------------- void __fastcall TForm1::endClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int i; Label3->Caption="現在時刻:" TimeToStr(Time()); sg->ColCount=4; sg->RowCount=36; for(i=1;iColCount;i ) { sg->ColWidths[i]=160; } sg->Cells[0][0]="SEQ"; sg->Cells[1][0]="Function"; sg->Cells[2][0]="Ext"; sg->Cells[3][0]="Status"; sg->Cells[1][1]="Static Test"; sg->Cells[2][1]="DO01-01; 48V@Light Load"; sg->Cells[1][2]="Frequency Test"; sg->Cells[2][2]="IF01-01"; sg->Cells[1][3]="ON/OFF Test"; sg->Cells[2][3]="ON01-01; 48V@Light Load"; sg->Cells[1][4]="Static Test"; sg->Cells[2][4]="DO01-01; 48V@Full Load"; sg->Cells[1][5]="ON/OFF Test"; sg->Cells[2][5]="ON01-01; 48V@Full Load"; sg->Cells[1][6]="Static Test"; sg->Cells[2][6]="DO01-01; 38.4V@Full Load"; sg->Cells[1][7]="ON/OFF Test"; sg->Cells[2][7]="ON01-01; 38.4V@Full Load"; sg->Cells[1][8]="Static Test"; sg->Cells[2][8]="DO01-01; 72V@Full Load"; sg->Cells[1][9]="ON/OFF Test"; sg->Cells[2][9]="ON01-01; 72V@Full Load"; for(i=1;iRowCount;i ) { sg->Cells[0][i]=i; } } //--------------------------------------------------------------------------- void __fastcall TForm1::sgDrawCell(TObject *Sender, int ACol, int ARow,TRect &Rect, TGridDrawState State) { if(ACol>0 && ARow>0) { if(sg->Cells[3][ARow]=="pass") { sg->Canvas->Brush->Color=clGreen; } else if(sg->Cells[3][ARow]=="fail") { sg->Canvas->Brush->Color=clRed; } /* { sg->Canvas->Brush->Color=clWhite; }*/ sg->Canvas->FillRect(Rect); sg->Canvas->TextOut(Rect.Left 2, Rect.Top 6,sg->Cells[ACol][ARow]); } } //--------------------------------------------------------------------------- void __fastcall TForm1::testClick(TObject *Sender) { int ok; /* PASS --> ok=1, FAIL --> ok=0 */ test_1(&ok); if (ok == 0) { sg->Cells[3][1]="fail"; sg->Repaint(); } else { sg->Cells[3][1]="pass"; sg->Repaint(); } test_2(&ok); if(ok==0) { sg->Cells[3][2]="fail"; sg->Repaint(); } else { sg->Cells[3][2]="pass"; sg->Repaint(); } test_3(&ok); if(ok==0) { sg->Cells[3][3]="fail"; sg->Repaint(); } else { sg->Cells[3][3]="pass"; sg->Repaint(); } test_4(&ok); if(ok==0) { sg->Cells[3][4]="fail"; sg->Repaint(); } else { sg->Cells[3][4]="pass"; sg->Repaint(); } test_5(&ok); if(ok==0) { sg->Cells[3][5]="fail"; sg->Repaint(); } else { sg->Cells[3][5]="pass"; sg->Repaint(); } test_6(&ok); if(ok==0) { sg->Cells[3][6]="fail"; sg->Repaint(); } else { sg->Cells[3][6]="pass"; sg->Repaint(); } test_7(&ok); if(ok==0) { sg->Cells[3][7]="fail"; sg->Repaint(); } else { sg->Cells[3][7]="pass"; sg->Repaint(); } test_8(&ok); if(ok==0) { sg->Cells[3][8]="fail"; sg->Repaint(); } else { sg->Cells[3][8]="pass"; sg->Repaint(); } test_9(&ok); if(ok==0) { sg->Cells[3][9]="fail"; sg->Repaint(); } else { sg->Cells[3][9]="pass"; sg->Repaint(); } //return(ok); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormShow(TObject *Sender) { //sg->Row=1; } //--------------------------------------------------------------------------- void test_1(int *ok) /* 48V @ Light Load */ { *ok=1; vol=random(10)*0.1 3; if((vol < 3.1)||(vol > 3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //-------------------------------------------------------- void test_2(int *ok) /* Frequency */ { *ok=1; delay(1.0); freq=random(500); if((freq<1)||(freq>500)) { *ok=0; return; } delay(1.0); freq=random(500); if((freq<1)||(freq>500)) { *ok=0; return; } return; } //--------------------------------------------------- void test_3(int *ok) /* ON/OFF Test 48V @ Light Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } return; } //----------------------------------------------- void test_4(int *ok) /* 48V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //-------------------------------------------------------- void test_5(int *ok) /* ON/OFF Test 48V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void test_6(int *ok) /* 38.4V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //----------------------------------------------------------- void test_7(int *ok) /* ON/OFF Test 38.4V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void test_8(int *ok) /* 72V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //----------------------------------------------------- void test_9(int *ok) /* ON/OFF Test 72V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1 3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1 1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1 12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void delay(double s) { double start,end; start=timeGetTime(); do { end=timeGetTime(); Application->ProcessMessages(); }while(((end-start)/CLK_TCK)<=s); } //-------------------------------------------------
------
Auston Huang
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-03-21 21:28:01 IP:61.221.xxx.xxx 未訂閱
引言: 各位大佬好: 採用你們的建議,寫一個delay的副函數,當主程式執行時testclick按下後,視窗內的元件已經可以控制,但為什麼程式執行時當我按下endclick,程式不會停止執呢?以下是我的程式碼: 滿長的,但最主要是endClick事件,是不是不應該放在endClick內?因為我希望當程式執行,能按下endClick來停止程式執行。 是因為testClick事件程序尚未執行完,就算按下endClick鍵,也無法終止執行嗎?請問各位大大那我應該怎麼做呢? //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include <math.h> #include #include "u41007T0_1u.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; float vol,freq; void delay(double s); void test_1(int *ok); void test_2(int *ok); void test_3(int *ok); void test_4(int *ok); void test_5(int *ok); void test_6(int *ok); void test_7(int *ok); void test_8(int *ok); void test_9(int *ok); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Timer1->Enabled=true; Timer1->Interval=1000; } //--------------------------------------------------------------------------- void __fastcall TForm1::endClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int i; Label3->Caption="現在時刻:"+TimeToStr(Time()); sg->ColCount=4; sg->RowCount=36; for(i=1;iColCount;i++) { sg->ColWidths[i]=160; } sg->Cells[0][0]="SEQ"; sg->Cells[1][0]="Function"; sg->Cells[2][0]="Ext"; sg->Cells[3][0]="Status"; sg->Cells[1][1]="Static Test"; sg->Cells[2][1]="DO01-01; 48V@Light Load"; sg->Cells[1][2]="Frequency Test"; sg->Cells[2][2]="IF01-01"; sg->Cells[1][3]="ON/OFF Test"; sg->Cells[2][3]="ON01-01; 48V@Light Load"; sg->Cells[1][4]="Static Test"; sg->Cells[2][4]="DO01-01; 48V@Full Load"; sg->Cells[1][5]="ON/OFF Test"; sg->Cells[2][5]="ON01-01; 48V@Full Load"; sg->Cells[1][6]="Static Test"; sg->Cells[2][6]="DO01-01; 38.4V@Full Load"; sg->Cells[1][7]="ON/OFF Test"; sg->Cells[2][7]="ON01-01; 38.4V@Full Load"; sg->Cells[1][8]="Static Test"; sg->Cells[2][8]="DO01-01; 72V@Full Load"; sg->Cells[1][9]="ON/OFF Test"; sg->Cells[2][9]="ON01-01; 72V@Full Load"; for(i=1;iRowCount;i++) { sg->Cells[0][i]=i; } } //--------------------------------------------------------------------------- void __fastcall TForm1::sgDrawCell(TObject *Sender, int ACol, int ARow,TRect &Rect, TGridDrawState State) { if(ACol>0 && ARow>0) { if(sg->Cells[3][ARow]=="pass") { sg->Canvas->Brush->Color=clGreen; } else if(sg->Cells[3][ARow]=="fail") { sg->Canvas->Brush->Color=clRed; } /* { sg->Canvas->Brush->Color=clWhite; }*/ sg->Canvas->FillRect(Rect); sg->Canvas->TextOut(Rect.Left+2, Rect.Top+6,sg->Cells[ACol][ARow]); } } //--------------------------------------------------------------------------- void __fastcall TForm1::testClick(TObject *Sender) { int ok; /* PASS --> ok=1, FAIL --> ok=0 */ test_1(&ok); if (ok == 0) { sg->Cells[3][1]="fail"; sg->Repaint(); } else { sg->Cells[3][1]="pass"; sg->Repaint(); } test_2(&ok); if(ok==0) { sg->Cells[3][2]="fail"; sg->Repaint(); } else { sg->Cells[3][2]="pass"; sg->Repaint(); } test_3(&ok); if(ok==0) { sg->Cells[3][3]="fail"; sg->Repaint(); } else { sg->Cells[3][3]="pass"; sg->Repaint(); } test_4(&ok); if(ok==0) { sg->Cells[3][4]="fail"; sg->Repaint(); } else { sg->Cells[3][4]="pass"; sg->Repaint(); } test_5(&ok); if(ok==0) { sg->Cells[3][5]="fail"; sg->Repaint(); } else { sg->Cells[3][5]="pass"; sg->Repaint(); } test_6(&ok); if(ok==0) { sg->Cells[3][6]="fail"; sg->Repaint(); } else { sg->Cells[3][6]="pass"; sg->Repaint(); } test_7(&ok); if(ok==0) { sg->Cells[3][7]="fail"; sg->Repaint(); } else { sg->Cells[3][7]="pass"; sg->Repaint(); } test_8(&ok); if(ok==0) { sg->Cells[3][8]="fail"; sg->Repaint(); } else { sg->Cells[3][8]="pass"; sg->Repaint(); } test_9(&ok); if(ok==0) { sg->Cells[3][9]="fail"; sg->Repaint(); } else { sg->Cells[3][9]="pass"; sg->Repaint(); } //return(ok); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormShow(TObject *Sender) { //sg->Row=1; } //--------------------------------------------------------------------------- void test_1(int *ok) /* 48V @ Light Load */ { *ok=1; vol=random(10)*0.1+3; if((vol < 3.1)||(vol > 3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //-------------------------------------------------------- void test_2(int *ok) /* Frequency */ { *ok=1; delay(1.0); freq=random(500); if((freq<1)||(freq>500)) { *ok=0; return; } delay(1.0); freq=random(500); if((freq<1)||(freq>500)) { *ok=0; return; } return; } //--------------------------------------------------- void test_3(int *ok) /* ON/OFF Test 48V @ Light Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } return; } //----------------------------------------------- void test_4(int *ok) /* 48V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //-------------------------------------------------------- void test_5(int *ok) /* ON/OFF Test 48V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void test_6(int *ok) /* 38.4V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //----------------------------------------------------------- void test_7(int *ok) /* ON/OFF Test 38.4V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void test_8(int *ok) /* 72V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if((vol<3.1)||(vol>3.5)) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if((vol<1.5)||(vol>1.9)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.31)||(vol>12.65)) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if((vol<12.33)||(vol>12.77)) { *ok=0; return; } return; } //----------------------------------------------------- void test_9(int *ok) /* ON/OFF Test 72V @ Full Load */ { *ok=1; delay(1.0); vol=random(10)*0.1+3; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(10)*0.1+1; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } delay(1.0); vol=random(100)*0.1+12; if(vol>1.0) { *ok=0; return; } return; } //-------------------------------------------------------- void delay(double s) { double start,end; start=timeGetTime(); do { end=timeGetTime(); Application->ProcessMessages(); }while(((end-start)/CLK_TCK)<=s); } //------------------------------------------------- >< face="Verdana, Arial, Helvetica">
ohsula 你好:
(1)建議你新增一個全域變數 (例如: bool gbStop;),用來當做是否停止工作的
   Flag
(2)當你的開始工作 Button 被按下的時候,先把這個 Flag 設為 false (例如
   gbStop=false)
(3)當你的停止工作 Button 被按下的時候,再把這個 Flag 設為 true (例如:
   gbStop=true)
(4)接下來,要特別注意,在你的程式碼中,所有迴圈的地方 (for, while...)
   都要加入以下的程式碼 (以 while 為例)
   while(...)
   {
      if(gbStop) break;
   }
(5)這樣子應該就可以把工作停止了
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
ohsula
一般會員


發表:12
回覆:17
積分:5
註冊:2004-03-02

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-03-24 23:04:04 IP:61.229.xxx.xxx 未訂閱
HomeSound大大你好: 你的意思是如果我要delay 50 msec的話,變數 s 就要設為0.05囉! #include  /* 主程式 */ { . . double s=0.050; delay(double s); . . . } void delay(double s) { double start,end; start=timeGetTime(); do { end=timeGetTime(); Application->ProcessMessages(); }while(((end-start)/CLK_TCK)<=s); } Auston Huang
------
Auston Huang
ohsula
一般會員


發表:12
回覆:17
積分:5
註冊:2004-03-02

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-03-24 23:06:37 IP:61.229.xxx.xxx 未訂閱
sorry, 程式碼更正為下: /* 主程式 */ { . . . delay(0.05); . . . } void delay(double s) { double start,end; start=timeGetTime(); do { end=timeGetTime(); Application->ProcessMessages(); }while(((end-start)/CLK_TCK)<=s); } Auston Huang
------
Auston Huang
HomeSound
中階會員


發表:44
回覆:178
積分:94
註冊:2002-08-31

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-04-02 04:06:25 IP:61.30.xxx.xxx 未訂閱
小弟上列的函數Delay跟Sleep()函數用法都一樣,1秒=Delay(1000); 可於Application->ProcessMessages();的後面加上 if(StopProg) break; //bool StopProg 全域變數 就像RaynorPao大佬說的原理一樣. --==多看.多學.多聽==--
------
--==多看.多學.多聽==--
系統時間:2024-07-01 3:23:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!