I/O Error 87

Hi all

I'm doing the code below and at the end, instead of stopping - it brings up the message : "I/O Error 87" (from EInOutError) .
I couldn't find anything about "Error 87" in the Delphi's help .
What is this Error ?

What am i doing wrong...?

The code :

const BufferSize = 1050;
var f                 : File;
      RBuffer     : array[1..BufferSize] of Byte;
      BufferLen : DWORD;
While Not EOF(F) Do
   BlockRead(f, RBuffer, SizeOf(RBuffer), BufferLen);

(the parts in the dots (..) REALLY don't have NOTHING to do files or buffering)

I'm using D5 Standart w/ win95 if it matters.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add this line
before your while statement and add this one
{$+} after the end of the while statement.
I usually do this:

const BufferSize = 1050;
var f                 : File;
     RBuffer     : array[1..BufferSize] of Byte;
     BufferLen : DWORD;

  BlockRead(f, RBuffer, SizeOf(RBuffer), BufferLen);
  // bufferLen returns with the number of bytes read
  if bufferLen > 0 then begin
    // blockread has just read bufferLen bytes into
    // RBuffer
until bufferLen = 0;

By the way, how did you open the file ?

If you did this:


then change to:


By default Delphi opens with 128 (reset(f,128)), wich means read and write blocks of 128 bytes.

So when you call:


you are actually reading sizeof(rbuffer) * 128 bytes.

Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

use a while loop like;

while(1=1) do begin
   BloackRead(F, Buffer, SizeOf(Buffer), BufferLen);
   if(BufferLen<SizeOf( Buffer)) then break;


Win32 Error codes:
87 The parameter is incorrect.  ERROR_INVALID_PARAMETER

I think MS99 is correct. Anyways I'd suggest to use TFileStream for such stuff since it's easier to use and offers less pitfalls (sharing modes, record sizes, bytes read...).

This would then be (CLASSES must be in the uses clause):

    Stream: TStream;

    Stream:=TFileStream.Create('Filename',fmOpenRead); //open file
    BufferLen:=Stream.Read(RBuffer,SizeOf(RBuffer)); //read block
    Stream.Free; //close stream

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ebi1Author Commented:
ThanX for the info guys

I'm a little new with the great Delphi so i didn't think that AvonWyss's way can be done
(and the 87 answer...)

BTW : I did opened the file with Reset(f, 1);

ThanX again guys.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.