Subject: Re: [fpc-pascal]Unknown RT error
Show quoted text 11 lines
Thomas;
>Hmm, my suggestion would be replacing the "reset (BinaryFile);"
>statement with a "reset (BinaryFile, 1)" since otherwise blockread
>tries to read the data in chunks of 128 Bytes not single bytes,
>e.g. BUFFERSIZE*128 bytes if I'm not mistaken.
But on my blockread statement I'm using sizeof (Buffer) -- which is a 32K
array of char -- to determine the block size to read from the file. I would
assume that blockread would then only try to read 32768 bytes, correct? Or
is that wrong...
From the documentation (about file handling):
------
"Blockread" reads count or less *records* from file F. A record is a block
of bytes with size specified by the Rewrite() or Reset() statement. [...]
"Reset" opens a file f for reading. [...] If F is an untyped file, the record size can be specified in the optional parameter L. A default value of
128 bytes is used. [...]
------
You didn't open the file as "file of char" or "file of byte" but as an untyped file.... hence the default record size for reading is 128 bytes and
not as expected one byte. The rtl doesn't adjust the i/o record size for each operation. It is set at the time you issue the reset() call and stays
the same while the file is open.
To solve your problem you either have to tell the rtl the default record size (if you use untyped files) or use a typed file handle (the record size
is derived from the typed file type information automatically at runtime)
Changing the declaration of BinaryFile to one of those mentioned should work
too.
The only thing I wasn't sure about was the default record size which I correctly remembered to be 128 bytes.
Thomas