I惴 having problems with the following code.
var
f: TextFile;
begin
if OpenDialog1.Execute then
begin { open a text file }
AssignFile(f, OpenDialog1.FileName);
>> Append(f);
Writeln(f, 'I am appending some stuff to the end of the file.');
{ insert code here that would require a Flush before closing the file }
Flush(f); { ensures that the text was actually written to file }
CloseFile(f);
end;
end;
It stops on the signed line (>>) and returns a exception :EInOutError with
the message 'I/O error 103
The file exists on the disk it was created with
FileCreate(PathLoc + '\log.txt'); statement.
What愀 wrong?
Thanks in Advance
Augusto From Brazil
This is probably your problem. Try the following
var I : integer;
I := FileCreate(PathLoc + '\log.txt');
FileClose(I);
Robert
> AssignFile(f, OpenDialog1.FileName);
>>> Append(f);
>It stops on the signed line (>>) and returns a exception :EInOutError with
>the message 'I/O error 103
>
>The file exists on the disk it was created with
>
>FileCreate(PathLoc + '\log.txt'); statement.
In addition to not having called FileClose, some other process may
have the file open exclusively.
Good luck.
Kurt
> In addition to not having called FileClose, some other process may
> have the file open exclusively.
You might be right, Kurt, as to the actual problem, (file creation has left
it open or something else holds it open) - but it needs assumptions that
there are typos in the post! - I'd expect 105 (access denied) then, not 103,
which is 'file not open' - 103 should not occur on an append .. (unless it
is a namespace problem and append does not do what we expect!) .. though it
might occur on the writeln .. (how could it reach that though, if the file
wasn't opened an exception should fire as there is no defence) .... enough,
lets see if he comes back!
>You might be right, Kurt, as to the actual problem, (file creation has left
>it open or something else holds it open) - but it needs assumptions that
>there are typos in the post! - I'd expect 105 (access denied) then, not 103,
>which is 'file not open' - 103 should not occur on an append .. (unless it
>is a namespace problem and append does not do what we expect!) .. though it
>might occur on the writeln .. (how could it reach that though, if the file
>wasn't opened an exception should fire as there is no defence) .... enough,
>lets see if he comes back!
Yes, or I/O error 32. 103 (in my help system) says "File not open" -
but that should happen on the write, not the Append.
But this could be a file on the network which can give strange errors,
so...
Kurt