faqts : Computers : Programming : Languages : Delphi

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

123 of 159 people (77%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Delphi: File: Error: I/O Error 103

Feb 18th, 2004 15:14
D Cooper, Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 02 September 2003 - 01:34 pm ------------------

Delphi: File: Error: I/O Error 103

Cause:

A file is assigned and then closed, but the file pointer has not
(for all possible cases) been reset or rewritten, in between.

---

Solution:

Reset or rewrite the file pointer in all possible cases.

---

The source code with the problem looks like this:

procedure TForm1.PROCFileCreateNew( filenameS : string );
var fP : TextFile;
begin
 AssignFile( fP, filenameS );
 if FNFileCheckExistNotB( filenameS ) then begin
  Reset( fP );
 end;
 Close( fP );
end;

Then the error occurs in Close( fP );

---

Solution:

You should in any case reset the file pointer (using 'reset'
or 'rewrite') between you 'assigned' the file until it reaches the
'close'.

E.g. like this:

procedure TForm1.PROCFileCreateNew( filenameS : string );
var fP : TextFile;
begin
 AssignFile( fP, filenameS );
 //
 // so you also cover all other possibilities
 // (like also in the other branch of the 'if')
 // between assign and close
 // by putting or a reset or a rewrite there
 //
 if FNFileCheckExistNotB( filenameS ) then begin
  Rewrite( fP );
 end
 else begin
  Reset( fP );
 end;
 Close( fP );
end;

----------------------------------------------------------------------

18 February 2004, 23:12. D Cooper

This can also be raised if you are trying to write out to a path that
does not exist. Example:

    AssignFile(tout, 'nope:\blag\b.html');
    Rewrite(tout);
    WriteLn(tout, data);
    CloseFile(tout);

----------------------------------------------------------------------