Write Procedure
procedure Write(var F: File; var Value; ...); procedure Write(Expr
:Width
:Precision
; ...); procedure Write(var F: TextFile;Expr
:Width
:Precision
; ...);
The Write
procedure writes text or other values to
a file. If you are writing to a binary file, you must supply a
variable of the same type as the file’s base type. You can
write multiple records by listing multiple variables as arguments to
the Write
procedure.
When writing to a TextFile
, you can write strings,
numbers, characters, and Boolean values. Each value can be followed
by the Width
and
Precision
expressions, separated by
colons. Width
and
Precision
can be any integer expressions.
Width
specifies the minimum size of the
string representation of Expr
, and
Precision
specifies the number of places
after the decimal point of a floating-point number.
Write
uses as many characters as it needs, so
Width
is just the suggested minimum width.
If the number requires fewer than Width
characters, Write
pads the string on the left with
blanks. If you do not supply a Width
,
Delphi uses 1 as the minimum width for integers and it prints
floating-point numbers as 26 characters in the following form:
'-1.12345678901234567E+1234'
If Expr
is a floating-point number,
Write
reduces the number of decimal places to fit
the value into a string that uses at most
Width
characters. Write
always uses at least one digit after the decimal place, though. You
can also supply a Precision
, which tells
Write
how many decimal places to use after the
decimal point. If you supply a Precision
,
Write
uses fixed-point notation instead of
exponential notation.
If the file has not been assigned, Write
reports
I/O error 102.
If the file is not open for write access, Write
reports I/O error 104.
When the write fails because the disk is full, sometimes
Write
reports the Windows error
Error_Disk_Full
(112); sometimes it reports I/O
error 101.
If no file is given as the first argument, Write
writes to the text file Output
.
The Str
procedure does the same thing as
Write
, except that it “writes” a
single value to a string instead of a file.