Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə198/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   194   195   196   197   198   199   200   201   ...   294
DelphiLanguageGuide

Text Files
This section summarizes I/O using file variables of the standard type Text.
When a text file is opened, the external file is interpreted in a special way: It is considered to represent a sequence
of characters formatted into lines, where each line is terminated by an end-of-line marker (a carriage-return character,
possibly followed by a line feed character). The type Text is distinct from the type file of Char.
For text files, there are special forms of Read and Write that let you read and write values that are not of type Char.
Such values are automatically translated to and from their character representation. For example, Read(F, I), where
I is a type Integer variable, reads a sequence of digits, interprets that sequence as a decimal integer, and stores it in I.
There are two standard text file variables, Input and Output. The standard file variable Input is a read-only file
associated with the operating system's standard input (typically, the keyboard). The standard file variable Output is
a write-only file associated with the operating system's standard output (typically, the display). Before an application
begins executing, Input and Output are automatically opened, as if the following statements were executed:
AssignFile(Input, '');
Reset(Input);
AssignFile(Output, '');
Rewrite(Output);
171


Note:
For Win32 applications, text-oriented I/O is available only in console applications, that is, applications
compiled with the Generate console application option checked on the Linker page of the Project Options
dialog box or with the -cc command-line compiler option. In a GUI (non-console) application, any attempt to
read or write using Input or Output will produce an I/O error.
Some of the standard I/O routines that work on text files don't need to have a file variable explicitly given as a
parameter. If the file parameter is omitted, Input or Output is assumed by default, depending on whether the
procedure or function is input- or output-oriented. For example, Read(X) corresponds to Read(Input, X) and Write
(X) corresponds to Write(Output, X).
If you do specify a file when calling one of the input or output routines that work on text files, the file must be associated
with an external file using AssignFile, and opened using Reset, Rewrite, or Append. An error occurs if you pass a
file that was opened with Reset to an output-oriented procedure or function. An error also occurs if you pass a file
that was opened with Rewrite or Append to an input-oriented procedure or function.
Untyped Files
Untyped files are low-level I/O channels used primarily for direct access to disk files regardless of type and
structuring. An untyped file is declared with the word file and nothing more. For example,
var DataFile: file;
For untyped files, the Reset and Rewrite procedures allow an extra parameter to specify the record size used in data
transfers. For historical reasons, the default record size is 128 bytes. A record size of 1 is the only value that correctly
reflects the exact size of any file. (No partial records are possible when the record size is 1.)
Except for Read and Write, all typed-file standard procedures and functions are also allowed on untyped files. Instead
of Read and Write, two procedures called BlockRead and BlockWrite are used for high-speed data transfers.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   194   195   196   197   198   199   200   201   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin