全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:809
推到 Plurk!
推到 Facebook!

SetFocus函式在Thread中無法發揮作用?

尚未結案
hornacek
一般會員


發表:29
回覆:76
積分:21
註冊:2004-02-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-14 14:54:54 IP:210.243.xxx.xxx 未訂閱
請問一下,我用Thread Object建立一個thread物件,將欲執行的程序放在thread的Execute()函式中,其中有寫到Edit1->SetFocus(),但卻沒有運作?其它部份都沒有問題,在之前Edit1->Enabled是false的,但我在寫SetFocus之前,有把它解開,也就是說如下的程式碼:
Thread::Execute()
{
   ...
   Edit1->Enabled = true;
   ...
   Edit1->SetFocus();
   ...
}
不知道是什麼原因,SetFocus沒有作用?感激...
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-20 02:23:58 IP:211.76.xxx.xxx 未訂閱
hornacek你好: VCL不是Thread safe,所以在Execute裡面不能直接執行有用到VCL的程式。作法是把那些程式碼包成一個函式,並且利用Synchronize()呼叫他們。 Executes a method call within the main VCL thread. typedef void __fastcall (__closure *TThreadMethod)(void); void __fastcall Synchronize(TThreadMethod &Method); Description Synchronize causes the call specified by Method to be executed using the main VCL thread, thereby avoiding multi-thread conflicts. If you are unsure whether a method call is thread-safe, call it from within the Synchronize method to ensure that it executes in the main VCL thread. Execution of the thread current is suspended while Method executes in the main VCL thread. Warning: Do not call Synchronize from within the main VCL thread. Doing so leads to an infinite loop. Note: You can also protect unsafe methods using critical sections or the multi-read exclusive-write synchronizer.
系統時間:2024-05-07 2:06:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!