Read
Jump to navigation
Jump to search
- For typed files, reads a file component into a variable.
- For text files, reads one or more values into one or more variables
- Declaration
- Typed files: procedure Read(F , V1 [, V2,...,Vn ] );
- Text files: procedure Read( [ var F: Text; ] V1 [, V2,...,Vn ] );
- Target
- Windows, Real, Protected
- Remarks
- With a type string variable
- Read reads all characters up to, but not including, the next end-of-line marker or until Eof(F) becomes True; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.
- After the first Read, each subsequent Read will see the end-of-line marker and return a zero-length string.
Use multiple Readln calls to read successive string values.
When the extended syntax is enabled, Read can read null-terminated strings into zero-based character arrays.
- With type integer or type real variables
- Read will skip any blanks, tabs, or end-of-line markers preceding the numeric string.
- If the numeric string does not conform to the expected format, an I/O error occurs, otherwise the value is assigned to the variable.
- The next Read will start with the blank, tab or end-of-line marker that terminated the numeric string.
Sample Code
{Eof.PAS} {Sample code for the Eof, Read, and Write functions (text files).} { For Windows: } { uses WinCrt, WinDos; } var F: Text; Ch: Char; begin { Get file to read from command line } Assign(F, ParamStr(1)); Reset(F); while not Eof(F) do begin Read(F, Ch); Write(Ch); { Dump text file } end; end.