Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset issues for textfile

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
This problem is really annoying me because as far as I can tell, this is the same code I've used a million times. I have the following code

Code:
filename := extractFilePath(application.exeName) + 'log.txt';
assignFile(log, filename);
if fileExists(filename) then
   reset(log)
else
   rewrite(log);

It works fine as long as the file doesn't already exist and the rewrite line is called. If the file already exists and the reset line is called then any attempts to write to it result in error 105 (file not open).

Any thoughts on this?
 
try using append instead of reset


Code:
procedure TThrd_debugger.AppendDebugFile;

var Handle       : Text;

begin
 {$I+}
   AssignFile(Handle,DebugFile);
   if Fileexists(DebugFile) then Append(Handle) else Rewrite(Handle);
   Write(Handle,DebugLines.Text);
   DebugLines.Clear;
   Flush(Handle);
   CloseFile(Handle);
 {$I-}
end;

--------------------------------------
What You See Is What You Get
 
Thanks, that worked fine. Kinda confusing though as I always used reset before :S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top