Board index » delphi » Strange error i/o error in while loop

Strange error i/o error in while loop

Hi guys, i can not make any sense of the following, i am writing to a file
in the following :

Reset(BookFile);
    while not eof(BookFile) do
      begin{problem?}
         Read(BookFile,Temp);
         Write(Bookfile,A_Book);
         CloseFile(bookfile);
      end;{problem?}

however when i include the Begin..end(the ones with problem in parenthesis)
i get an I/O error 103, when i remove the begin..end everything is fine. Why
should this occur in the while loop?

 

Re:Strange error i/o error in while loop


103: File not open

What happens without the begin/end frame is that you just repeat the single
read statement until
end of file, then you write (once) and closefile, that's all

With the begin/end frame included you do:

begin
 Read
 Write
 CloseFile
end
begin
 Read . . . . . but now the file is no longer open!
 ...

I hope this brings you forward?

regards Sven

Quote
Nitesh <nit...@kivtronics.co.za> wrote in message

news:83l8ca$ob217@forums.borland.com...
Quote
> Hi guys, i can not make any sense of the following, i am writing to a file
> in the following :

> Reset(BookFile);
>     while not eof(BookFile) do
>       begin{problem?}
>          Read(BookFile,Temp);
>          Write(Bookfile,A_Book);
>          CloseFile(bookfile);
>       end;{problem?}

> however when i include the Begin..end(the ones with problem in
parenthesis)
> i get an I/O error 103, when i remove the begin..end everything is fine.
Why
> should this occur in the while loop?

Re:Strange error i/o error in while loop


Move the CloseFile call outside the begin/end block. As your code stands you
are closing the file after the first write then trying to read it on the
next pass through the loop.

--
Bill

Bill Todd (TeamB)
(TeamB cannot respond to questions received via email)

Other Threads