如果程序在同一个目录下这样吧: procedure TForm1.Button1Click(Sender: TObject); begin AssignFile(F,ExtractFilePath(Application.ExecName)+'\test.txt'); {Assigns the Filename} if FileExist(ExtractFilePath(Application.ExecName)+'\test.txt') then Reset(F) else Rewrite(F); Append(F); {Opens the file for editing} Writeln(F,'You have written text into a .txt file'); Closefile(F); {Closes file F} end;
在使用时先把出问题的那个窗体free掉,在重新用create,
就是form1.free;
再把project中的form1的创建代码拷贝过来就可以了.(只有一行代码)
procedure TForm1.Button1Click(Sender: TObject);
begin
AssignFile(F,ExtractFilePath(Application.ExecName)+'\test.txt');
{Assigns the Filename}
if FileExist(ExtractFilePath(Application.ExecName)+'\test.txt') then
Reset(F)
else
Rewrite(F);
Append(F); {Opens the file for editing}
Writeln(F,'You have written text into a .txt file');
Closefile(F); {Closes file F}
end;