Board index » delphi » reading past eof

reading past eof

With the following:

 Assign(f,RecordFile);
 ReSet(f);
 while not eof(f)
 read(f,Data);

I occasionally get 'Disk Read Error' as if trying to read past eof.Is an eof
marker automatically at the end of every file? Why am I attemting to read past
it?

Linden W.

 

Re:reading past eof


Quote
> With the following:

>  Assign(f,RecordFile);
>  ReSet(f);
>  while not eof(f)
>  read(f,Data);

> I occasionally get 'Disk Read Error' as if trying to read past eof.Is an eof
> marker automatically at the end of every file? Why am I attemting to
> read past it?
>    Yes, insofar as DOS is concerned, and TP/BP should always pick up the

condition.  I assume (1) Data is a record of the same type as the file
and (2) your code is more like:

Var file_var : file of rec_type;
    data_var : rec_type;
...
  Assign (F,file_var); Reset (F);
  while not EOF (F) do
    begin
      Read (F,data_var);
    ... process the data record
    end;

   If that's all the case, you shouldn't be seeing the error condition
you describe...8<}}

Re:reading past eof


In article <51ad9e$...@imsai.canuck.com>,
   lwil...@canuck.com (Linden Willms) wrote:

Quote
>With the following:

> Assign(f,RecordFile);
> ReSet(f);
> while not eof(f)
> read(f,Data);

>I occasionally get 'Disk Read Error' as if trying to read past eof.Is an eof
>marker automatically at the end of every file? Why am I attemting to read
past
>it?

>Linden W.

Maybe your last record is broken in your file. Let suppose that the last
record is only the half of it. Before you read it EOF is not set.
Then you try to read a record which is more than the rest of your file.

If the end of your file gets cut some way you will most probably get this
error.

Make sure that you write your file the very same way as you read it (same
records, noting else)

It can be real physical error as well.

SzP.

Szaszvari Peter
(http://iap11.ethz.ch/users/szp/szp.htm)

Other Threads