next up previous contents index
Next: Blockwrite Up: Functions and Procedures Previous: Assign

Blockread

   

Declaration:

Procedure Blockread (Var F : File; Var Buffer; Var Count : Longint [; var Result : Longint]) ;

Description:

Blockread reads count or less records from file F. The result is placed in Buffer, which must contain enough room for Count records. The function cannot read partial records.

If Result is specified, it contains the number of records actually read. If Result isn't specified, and less than Count records were read, a run-time error is generated. This behavior can be controlled by the {$i} switch.

Errors:

If Result isn't specified, then a run-time error is generated if less than count records were read.

See also:

Blockwrite,Reset, Assign

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));
end.



Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998