[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'System' (#rtl)

BlockRead

Read data from an untyped file into memory

Declaration

Source position: line 0

procedure BlockRead(

  var f: ;

  var Buf;

  count: Int64;

  var Result: Int64

);

procedure BlockRead(

  var f: ;

  var Buf;

  count: LongInt;

  var Result: LongInt

);

procedure BlockRead(

  var f: ;

  var Buf;

  count: Cardinal;

  var Result: Cardinal

);

procedure BlockRead(

  var f: ;

  var Buf;

  count: Word;

  var Result: Word

);

procedure BlockRead(

  var f: ;

  var Buf;

  count: Word;

  var Result: Integer

);

procedure BlockRead(

  var f: ;

  var Buf;

  count: Int64

);

Description

Blockreadreads countor less records from file F. A record is a block of bytes with size specified by the Rewriteor Resetstatement. The result is placed in Buffer, which must contain enough room for Countrecords. The function cannot read partial records. If Resultis specified, it contains the number of records actually read. If Resultisn't specified, and less than Countrecords were read, a run-time error is generated. This behavior can be controlled by the \var{\{\$i\}} switch.

Errors

Depending on the state of the \var{\{\$I\}} switch, a runtime error can be generated if there is an error. In the \var{\{\$I-\}} state, use IOResultto check for errors.

See also

Blockwrite

  

Write data from memory to an untyped file

Close

  

Close a file

Reset

  

Open file for reading

Assign

  

Assign a name to a file

Example

Program Example6;

{ Program to demonstrate the BlockRead and BlockWrite functions. }

Var Fin, fout : File;
    NumRead,NumWritten : Word;
    Buf : Array[1..2048] of byte;
    Total : Longint;

begin
  Assign (Fin, Paramstr(1));
  Assign (Fout,Paramstr(2));
  Reset (Fin,1);
  Rewrite (Fout,1);
  Total:=0;
  Repeat
    BlockRead (Fin,buf,Sizeof(buf),NumRead);
    BlockWrite (Fout,Buf,NumRead,NumWritten);
    inc(Total,NumWritten);
  Until (NumRead=0) or (NumWritten<>NumRead);
  Write ('Copied ',Total,' bytes from file ',paramstr(1));
  Writeln (' to file ',paramstr(2));
  close(fin);
  close(fout);
end.