System.BlockRead
Delphi
function BlockRead(var F: File; var Buf; Count: Integer; [var Result: Integer]): Integer; overload;
function BlockRead(var F: File; var Buf; Count: Integer; [var Result: Integer]): Integer; overload;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.pas | System | System |
Description
Reads one or more records from an open file into a variable.
Warning: This is an older method that is particularly dangerous to use because of the untyped
Buf
parameter, leading to potential memory corruption. The record size used by BlockRead and BlockWrite is governed by the optional 2nd parameter to the Reset or Rewrite call that was used to open the file being written. It is preferable to use streams in your applications. For example, a user procedure involving a stream can use both TMemoryStreams and TFileStreams, instead of being limited to using files as with these older routines.
F
is an untyped file variable, Buf
is any variable, Count
is an expression of type Integer, and Result
is an optional variable of type Integer.
BlockRead reads Count
or fewer records from the file F
into memory, starting at the first byte occupied by Buf
. The actual number of complete records read (less than or equal to Count
) is returned in Result
.
The entire transferred block occupies at most Count
*RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was not specified).
If the entire block was transferred, Result
is equal to Count
.
If Result
is less than Count
, BlockRead reached the end of the file before the transfer was complete. If the file's record size is greater than 1, Result
returns the number of complete records read.
If Result
is not specified, an I/O error occurs if the number of records read is not equal to Count
. If the {$I+} compiler directive is in effect, errors raise an EInOutError exception.
See Also
- BlockWrite
- Using Streams to Read or Write Data
- Streams, Reader and Writers
- File Input and Output Support
- Delphi Intrinsic Routines
- TFileStream
- TStreamReader
- TStreamWriter
- EInOutError
- Rewrite
- Reset
- AssignFile
- CloseFile