誰能幫我實現這個小功能? 80分送上,很好得的. :)

whyNotHere 2004-11-11 07:17:09
題目為:button1.Click創建一個E:\one.txt 文件, 然後往其中按順序加入'a', 'b', 'c'
也就是說: 不管button1 click多少次, one.txt中的內容始終為:
a
b
c

===================================================================
我寫了如下, 不知道錯在哪了,它說:I/O error 32. 哪位高手能給我一個正確的完善的程序, 多謝了!
FileCreate ('E:\one.txt');
AssignFile (f, 'E:\one.txt');
append (f);
writeln(f, 'a');
writeln(f, 'b');
writeln(f, 'c');
...全文
77 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cappuccino 2004-11-11
  • 打赏
  • 举报
回复
回复人: postfxj(探索者) ( ) 信誉:100
写的是正确的
王集鹄 2004-11-11
  • 打赏
  • 举报
回复
// 看这样可以不?~~ 注意:Flush、CloseFile都不能少~~
var
f: TextFile;
begin
FileClose(FileCreate('c:\temp\one.txt'));
AssignFile(f, 'c:\temp\one.txt');
Append(f);
Writeln(f, 'a');
Writeln(f, 'b');
Writeln(f, 'c');
Flush(f);
CloseFile(f);
end;
王集鹄 2004-11-11
  • 打赏
  • 举报
回复
ksaiy :)
postfxj 2004-11-11
  • 打赏
  • 举报
回复
var
f:TextFile;
begin
AssignFile (f, 'E:\one.txt');
Rewrite(f);
Writeln(f, 'a');
Writeln(f, 'b');
Writeln(f, 'c');
CloseFile(f);
whyNotHere 2004-11-11
  • 打赏
  • 举报
回复
對不起, 我的代碼總體來講是這樣的,

button1.Click中使用一個循環創建了幾十個文本文檔(1.txt, 2.txt,3.txt...),
我是使用FileCreate 函數來創建的。
然後button2.Click中再用一個循環往這些文本文檔中寫數據

所以在我的系統中必須要先創建文本文檔,然後獲得局柄,再寫值,
而不好每一個文件都先有局柄,再創建, 所以你給的方法我不好用. :)

看看我的代碼:為什麼會有錯?
FileCreate ('E:\one.txt');
AssignFile (f, 'E:\one.txt');
append (f);
writeln(f, 'a');
writeln(f, 'b');
writeln(f, 'c');
ksaiy 2004-11-11
  • 打赏
  • 举报
回复
呵呵。用伴水兄的方法可以了。

伴水兄好久不见了。
王集鹄 2004-11-11
  • 打赏
  • 举报
回复
var
f: System.Text;
begin
AssignFile(f, 'c:\temp\one.txt');
Rewrite(f);
Writeln(f, 'a');
Writeln(f, 'b');
Writeln(f, 'c');
CloseFile(f);
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧