From RAD Studio API Documentation
Jump to: navigation, search


procedure BlockWrite(var F: File; const Buf; Count: Integer); overload;
procedure BlockWrite(var F: File; const Buf; Count: Integer; var Result: Integer); overload;


Type Visibility Source Unit Parent
procedure public System.pas System System


Writes one or more records from a variable to an open file.

Warning: This is an older method that is particularly dangerous to use because of the untyped parameter, leading to potential memory corruption. The record size used by BlockWrite and BlockRead is governed by the optional 2nd parameter to the Reset or Rewrite calls 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 as well as TFileStreams, instead of being limited to using files as happens 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.

BlockWrite writes Count or fewer records to the file F from memory, starting at the first byte occupied by Buf. The actual number of complete records written (less than or equal to Count) is returned in Result.

The entire block transferred occupies at most Count*RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was unspecified).

If the entire block is transferred, Result is equal to Count on return.

If Result is less than Count, the disk became full before the transfer was complete. In this case, if the file's record size is greater than 1, Result returns the number of complete records written.

BlockWrite advances the current file position by Result records.

If Result is not specified, an I/O error occurs if the number written is not equal to Count. If the {$I+} compiler directive is in effect, errors raise an EInOutError exception.

See Also

Code Examples