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

請教TextFile 的closeFile 問題

尚未結案
cmc92
一般會員


發表:3
回覆:13
積分:3
註冊:2003-11-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-11 10:26:56 IP:163.13.xxx.xxx 未訂閱
請教各位前輩高手 我用delphi 7.0 的textfile 輸出檔案,但closefile後,都要完全將主程式結束後資料才能真正寫入,並將檔案正常close 若不將主程式結束,在檔案總管內,看到的檔案大小會是 0 k 而且如果不退出主程式,再執行一次寫入的動作(同一檔案名稱), 就會出現i/o error 32的訊息 AssignFile(F, sfilename); Rewrite(F); Writeln(F,'123'); closefile(F); 不知可以什麼方法解決, 謝謝 !
william
版主


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-11 11:02:29 IP:147.8.xxx.xxx 未訂閱
Could the function Flush help? ================================================================= Flush function Empties the buffer of a text file opened for output. Unit System Category Text file routines Delphi syntax: function Flush(var t: Text): Integer; Description F is a text file variable. When a text file is opened for output using Rewrite or Append, Flush empties the file's buffer. This guarantees that all characters written to the file at that time have actually been written to the external file. Flush has no effect on files opened for input. Flush returns 0 if the operation succeeded. Otherwise, it returns the error code. When compiled using the {$I-} flag, the IOResult method returns this value. Note: {$I } handles runtime errors using exceptions. When using {$I-}, use IOResult to check for I/O errors.
cashxin2002
版主


發表:231
回覆:2555
積分:1937
註冊:2003-03-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-11 11:09:48 IP:63.84.xxx.xxx 未訂閱
您好﹗    ReWrite函數開啟的Text File會先把檔案中所有的內容先做刪除﹐再將新的內容存入﹐有點像OverWrite的方法﹐有另外一個Append的函數﹐使用方法和ReWrite一樣﹐但其功能是追加存入﹐不會刪掉原有的內容﹒    您的 F 變數宣告形態是File吧﹐請將其改為TextFile﹐再在CloseFile(F);這一句之前加上Flush(F); 作用是更新檔案內容﹒ 參考看看﹗ ===================== 努力,相信會獲得美麗! 忻晟 發表人 - cashxin2002 於 2003/12/11 11:19:49
------
忻晟
cmc92
一般會員


發表:3
回覆:13
積分:3
註冊:2003-11-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-15 08:52:06 IP:163.13.xxx.xxx 未訂閱
謝謝大家的幫忙 !! flush is nice 不過好像沒有用咧 我的作法是 Form A -->call FormB--> formB 內有個writeTEXT檔的function 我本來在 FormB的 onclose 順便 CloseFile(F) <後來又加上Flush(F)> 但結果好像一樣,不知是否不能在Form 的onClose 做closefile(F)這件事 後來我就在 FormA 內直接在 FormB.free前再執行一次 closefile(formb.F) 好像就可以啦~~ 因為我要用 writeln , 所以 F 不能宣告為 File 我一定要用 textfile ~~~ 不過 anyway 謝謝大家 這個討論區,真是個好地方 ~~~
系統時間:2024-06-24 20:31:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!