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
Begin
   ..
   ..
   BlockRead(f, RBuffer, SizeOf(RBuffer), BufferLen);
   ..
   ..
End;

(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.
ThanX
ebi1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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

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


repeat
  ...
  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
  end;
until bufferLen = 0;



0
ms99Commented:
By the way, how did you open the file ?

If you did this:

assignFile(f,'file.dat');
reset(f);

then change to:

reset(f,1);

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

So when you call:

blockread(f,rbuffer,sizeof(rbuffer),bufferLen)

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




0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

new_xCommented:
use a while loop like;

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

CloseFile.....


Regards,
0
AvonWyssCommented:
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):

var
    Stream: TStream;

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

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.
0
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
Delphi

From novice to tech pro — start learning today.