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

about thread

尚未結案
asan
一般會員


發表:5
回覆:8
積分:2
註冊:2003-05-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-27 00:21:44 IP:61.59.xxx.xxx 未訂閱
file2 := file; a := 0; while (FileExists( path '\' file2) = true) or (FileExists( path '\' file2 '.td!') = true) do begin a := a 1; file2 := inttostr(A) '_' file ; end; try ForceDirectories(path); fs := TFileStream.Create(path '\' file2 '.td!',fmCreate); except file_err := 1; end; 有一個 thread 他會檢查是否有相同的檔名 如果有就給他一個流水號 如 a a_1 , a_2,a_3 但是因為 thread 是一次開五個 所以有些這個檢查程序會出問題 不知道開如何解決
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-27 01:02:01 IP:211.22.xxx.xxx 未訂閱
 
var
 LockThis:TCriticalSection; // global variable, prevent other thread enter at same time      LockThis.Acquire;      file2 := file;
  a := 0;      while (FileExists( path   '\'   file2) = true) or (FileExists( path   '\'   file2   '.td!') = true) do
  begin
   a := a 1;
   file2 := inttostr(A)   '_'   file ;
  end;
 try 
  try
   ForceDirectories(path);
   fs := TFileStream.Create(path   '\'   file2   '.td!',fmCreate);
  except
   file_err := 1;
  end;
 finally
  LockThis.Release; 
 end;
------------------- 學,然後知不足。 發表人 - stallion 於 2005/07/27 01:08:03
ppp
一般會員


發表:1
回覆:3
積分:0
註冊:2004-03-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-27 14:33:32 IP:140.121.xxx.xxx 未訂閱
我剛好也有這個困擾 :)    Stallion的程式我又加上 LockThis := TCriticalSection.Create;  這樣才能跑    如果我一次開 10個 thread 那應該會做出 10 個檔名, 例如 test, 1_test, 2_test, 3_test... 9_test      但是似乎沒有用. 檔案只會出現 test , 1_test , 2_test 幾個 其他 thread 還是沒把檔案給建立出來, 我還缺了什麼嗎?        mythread.excute(); var  LockThis:TCriticalSection; // global variable, prevent other thread enter at same time  a, file_err : integer;  file, file2, path : string;    begin      LockThis := TCriticalSection.Create; LockThis.Acquire; file2 := file; a := 0; path := 'c:\test'; while (FileExists( path '\' file2) = true) or (FileExists( path '\' file2 '.td!') = true) do begin a := a 1; file2 := inttostr(a) '_' file ; end; try try ForceDirectories(path); fs := TFileStream.Create(path '\' file2 '.td!',fmCreate); except file_err := 1; end; finally LockThis.Release; end; end;
asan
一般會員


發表:5
回覆:8
積分:2
註冊:2003-05-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-27 22:10:50 IP:59.104.xxx.xxx 未訂閱
我試了~也跟~ppp大大一樣ㄟ~ 怎麼辦~到底那裡還要改~~
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-07-28 20:34:55 IP:211.22.xxx.xxx 未訂閱
抱歉,舉了例子忘了說明完整用法~ > ------------------- 學,然後知不足。
ppp
一般會員


發表:1
回覆:3
積分:0
註冊:2004-03-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-07-30 01:59:19 IP:211.21.xxx.xxx 未訂閱
Stallion : 可以了, 果然是我的宣告放錯地方 感謝您的幫忙
asan
一般會員


發表:5
回覆:8
積分:2
註冊:2003-05-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-07-30 10:37:01 IP:61.59.xxx.xxx 未訂閱
引言: Stallion : 可以了, 果然是我的宣告放錯地方 感謝您的幫忙
太好了~我也可以用了~3q pp & s
Ktop_Robot
站務副站長


發表:0
回覆:3511
積分:0
註冊:2007-04-17

發送簡訊給我
#8 引用回覆 回覆 發表時間:2007-04-30 13:44:05 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-07-05 0:55:19
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!