Name

Read Procedure

Syntax

procedure Read(var F: File; var Variable; ...);
procedure Read(var F: TextFile; var Variable; ...);
procedure Read(var Variable; ...);

Description

The Read procedure reads data from a binary or text file. It is not a real procedure.

To read from a typed binary file, the Variable must be of the same type as the base type of the file. Delphi reads one record from the file into Variable and advances the file position in preparation for reading the next record. If the file is untyped, Delphi reads as many bytes as specified for the record size when the file was opened with Reset. You can list more than one variable as arguments to Read, in which case, Read will read multiple records and assign each one to a separate variable.

When reading from a TextFile, Read performs a formatted read. Delphi reads characters from the input file and interprets them according to the type of each Variable. Read skips over white space characters (blanks, tabs, and ends of lines) when reading a number, and stops reading when it gets to another white space character.

When reading strings and characters, Read does not skip over white space. If Variable is a long string, Read reads the entire line into the string, but not the end-of-line characters. If Variable is a short string, Read stops at the end of the line or the size of the string, whichever comes first.

Errors

  • If the file has not been assigned, Read reports I/O error 102.

  • If the file is not open for read access, Read reports ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.