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

靈異還是delphi 的bug?

尚未結案
Lordaeron
初階會員


發表:24
回覆:93
積分:33
註冊:2004-05-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-19 00:47:26 IP:220.135.xxx.xxx 未訂閱
我有一支程式,  VCL main thread  -> create client thread -> create log object 中間會將 memo1.lines 當 TStrings 傳到 client thread, 再由 client thread 傳給log object 但很奇怪的是 log object 會寫log 到memo1 和 file (用傳統的assignfile 和wirteln), 跑一跑, 我client thread 又未結束, 就會出現access violation. 出現時間不定, 有時跑很久才會出現, 一出現就整支down 掉了. 看一下writeln 寫的log 和畫面上的不一致, 它只有write 大半到file 中. infop,asciip 都已getmem 64 K 了, BufRev 也確定有getmem 但就是會出現ACCESS violation. 每次查log file 都是寫了大半.    procedure TLogger.dump(BufRev:pchar;receivelength:integer); var   infoi:integer;   asciii:integer; begin   i:=-1;   infoi:=-1;   asciii:=-1;   inc(i);   inc(infoi);   inc(asciii);   info:='';   sTotal:='';   try   while i#31) and ((BufRev i)^<#127) then begin (asciip asciii)^:=' '; inc(asciii); (asciip asciii)^:=(BufRev i)^; inc(asciii); end else begin (asciip asciii)^:=' '; inc(asciii); (asciip asciii)^:='.'; inc(asciii); end; inc(i) end;// end while i
william
版主


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-19 10:21:14 IP:147.8.xxx.xxx 未訂閱
VCL is not thread safe, you need to use Synchorize in your client thread in order to update the GUI. http://pywong.hk.st http://www.lazybones.ca
SnoopyChen
一般會員


發表:1
回覆:17
積分:18
註冊:2003-07-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-19 10:28:14 IP:220.132.xxx.xxx 未訂閱
千萬不可在child thread中直接去異動main thread的VCL元件內容, 可以在child thread中透過Synchronize交由main thread來代替執行。 即使你是將memo.lines當成TStringList傳入child thread, 但child thread異動了這個TStringList卻也觸發memo的事件, 這時會產生訊息 交由main thread來執行, 因此很有可能產生了main/child thread 同時在存取memo.lines的內容, 故會出問題。
Lordaeron
初階會員


發表:24
回覆:93
積分:33
註冊:2004-05-19

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-19 11:32:16 IP:220.135.xxx.xxx 未訂閱
引言: 千萬不可在child thread中直接去異動main thread的VCL元件內容, 可以在child thread中透過Synchronize交由main thread來代替執行。 即使你是將memo.lines當成TStringList傳入child thread, 但child thread異動了這個TStringList卻也觸發memo的事件, 這時會產生訊息 交由main thread來執行, 因此很有可能產生了main/child thread 同時在存取memo.lines的內容, 故會出問題。
不會有你們講的問題 因為我只起一個thread, 而mainthread 也沒有access tmemo 的動作 除非client thread 停下來,中間沒有鬼打架的情形. 再說, 我寫在client thread 中的dump procedure 除了不寫檔以外. 功能和log object 的完全一樣, 就跑很久都沒事. 而且, 如果是Synchronize 的問題, 我根本不可能知道, 畫面上的和 寫入檔案的有不一致的情形;
william
版主


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-19 11:49:27 IP:147.8.xxx.xxx 未訂閱
Visual components MUST be accessed by the MAIN thread only. http://pywong.hk.st http://www.lazybones.ca
系統時間:2024-06-27 0:53:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!