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

執行緒跑圖,結果會快慢不定。

尚未結案
bcshahuo
一般會員


發表:28
回覆:28
積分:11
註冊:2005-01-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-27 15:41:57 IP:61.219.xxx.xxx 未訂閱
Procedure Tstart_map.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Begin //移動設定 rx_left := x - round(rxgifanimator1.width / 2); rx_Top := y - round(rxgifanimator1.height / 2); thread1 := tmyfirstthread.Create(false); thread1.Priority := tpnormal; thread1.FreeOnTerminate := true; End; ↑這是我在點滑鼠時,讓圖片知道他該往哪裡跑 Procedure TMyFirstThread.Execute; Begin //移動設定 While (start_map.rxgifanimator1.Left <> rx_left) Or (start_map.rxgifanimator1.top <> rx_top) Do Begin If rx_left > start_map.rxgifanimator1.Left Then Begin start_map.rxgifanimator1.Left := start_map.rxgifanimator1.Left 1; End; If rx_left < start_map.rxgifanimator1.Left Then Begin start_map.rxgifanimator1.Left := start_map.rxgifanimator1.Left - 1; End; If rx_top > start_map.rxgifanimator1.top Then Begin start_map.rxgifanimator1.top := start_map.rxgifanimator1.top 1; End; If rx_top < start_map.rxgifanimator1.top Then Begin start_map.rxgifanimator1.top := start_map.rxgifanimator1.top - 1; End; start_map.Refresh; End; { Place thread code here } End; ↑這是我放在執行緒中的迴圈。 想請問各位大大,我在按第一次時,他是正常的,還可以按另外一個button 秀出message,且圖片的速度是慢慢的。 在按了第二次,圖片速度加快了,且button也不能按了,等於是沒有執行緒在 執行。 後面的就不一定了,有時行有時不行。 請問各位大大,這是什麼原因?謝謝
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-27 16:20:05 IP:147.8.xxx.xxx 未訂閱
VCL is not thread safe. You should not access any visual component inside your thread without using synchroize.    http://pywong.hk.st http://www.lazybones.ca
bcshahuo
一般會員


發表:28
回覆:28
積分:11
註冊:2005-01-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-27 16:46:36 IP:61.219.xxx.xxx 未訂閱
引言: VCL is not thread safe. You should not access any visual component inside your thread without using synchroize. http://pywong.hk.st http://www.lazybones.ca
請問板主大大 synchronize(execute);放在迴圈中嗎? 不好意思大大,我對這不大了解怎用。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-27 17:48:44 IP:147.8.xxx.xxx 未訂閱
Synchorize wouldn't do any good for you in this case. You need to use the MAIN thread in accessing visual components and your thread is designed to move visual controls only? What do you want to do exactly?    http://pywong.hk.st http://www.lazybones.ca
bcshahuo
一般會員


發表:28
回覆:28
積分:11
註冊:2005-01-25

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-27 18:02:24 IP:61.219.xxx.xxx 未訂閱
引言: Synchorize wouldn't do any good for you in this case. You need to use the MAIN thread in accessing visual components and your thread is designed to move visual controls only? What do you want to do exactly? http://pywong.hk.st http://www.lazybones.ca
我是想做,類似電玩裡,用滑鼠控制人物,點上,他人就往上,點下就往下。 但,如果看到前方有敵人,就得馬上退後。 之前下了個指令是往前,但因為突發事件,而要退後。 這是我想用執行緒的地方。 但因為我是寫在同一個mouse_move裡面,我不知道有何方式可以變得和 電玩遊戲裡面一樣的人物走動。 感謝板主大大
系統時間:2024-05-01 14:49:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!