BlockRead Procedure
procedure BlockRead(var F: File; var Buffer; Count: Integer); procedure BlockRead(var F: File; var Buffer; Count: Integer; var RecordCount: Integer);
Call BlockRead
to
read Count
records from a binary file into
Buffer
. If F
is an untyped
file, BlockRead
uses the record size that you
specified when opening the file with Reset
. If you
supply the RecordCount
variable,
BlockRead
stores in it the number of records
actually read. In the case of an error or end of file,
RecordCount
might be less than
Count
. BlockRead
is not a real
procedure.
If you do not supply the RecordCount
argument, and
BlockRead
encounters an error or end of file, it
reports I/O error 100.
If the file is not open, BlockRead
reports I/O
error 103.
The Buffer
argument is not a pointer, but an
untyped var
parameter. Pass the actual variable,
not its address. If you have a pointer to a dynamically allocated
buffer, dereference the pointer when calling
BlockRead
.
The two most common uses for BlockRead
are to read
many records at once and to read complex data structures that do not
fit neatly into a simple typed file. For example, suppose a file
contains a four-byte string length, followed by the string’s
contents, and you want to read the data into a long string. In that
case, you need to read the length and the string contents separately,
as shown in the example.