Write
Writes to a text file.
Structure
Write( [var F: Text; ] P1 [ , P2,..., Pn] );
Parameters
Description
Write writes one or more values to a text file. F, if specified, is a text file variable. If F is omitted, the standard file variable Output is assumed. Each P is a write parameter. Each write parameter includes an output expression whose value is to be written to the file. A write parameter can also contain the specifications of a field width and a number of decimal places. Each output expression must be of a type Char, one of the Integer types (Byte, Shortint, Word, Longint, Cardinal), one of the floating-point types (Single, Real, Double, Extended, Currency), one of the string types (PChar, AnsiString, ShortString), a packed string, or one of the Boolean types (Boolean, Bool).
A write parameter has the form
OutExpr [: MinWidth [: DecPlaces ] ]
where OutExpr is an output expression. MinWidth and DecPlaces are type integer expressions.
MinWidth specifies the minimum field width, which must be greater than 0. Exactly MinWidth characters are written (using leading blanks if necessary) except when OutExpr has a value that must be represented in more than MinWidth characters. In that case, enough characters are written to represent the value of OutExpr. Likewise, if MinWidth is omitted, then the necessary number of characters are written to represent the value of OutExpr.
DecPlaces specifies the number of decimal places in a fixed-point representation of one of the Real types. It can be specified only if OutExpr is one of the Real types, and if MinWidth is also specified. When MinWidth is specified, it must be greater than or equal to 0.
Write with a character-type value:
If MinWidth is omitted, the character value of OutExpr is written to the file. Otherwise, MinWidth - 1 blanks followed by the character value of OutExpr is written.
Write with one of the integer type values:
If MinWidth is omitted, the decimal representation of OutExpr is written to the file with no preceding blanks. If MinWidth is specified and its value is larger than the length of the decimal string, enough blanks are written before the decimal string to make the field width MinWidth.
Write with one of the real type values:
If OutExpr has one of the real type values, its decimal representation is written to the file. The format of the representation depends on the presence or absence of DecPlaces.
If DecPlaces is omitted (or if it's present but has a negative value), a floating-point decimal string is written. If MinWidth is also omitted, a default MinWidth of 17 is assumed; otherwise, if MinWidth is less than 8, it's assumed to be 8. The format of the floating-point string is
[ | - ] <digit> . <decimals> E [ + | - ] <exponent>
The following table lists the components of the output string.
Component Meaning
[ | - ] ' ' or '-', according to the sign of OutExpr
<digit> Single digit, '0' only if OutExpr is 0
<decimals> Digit string of MinWidth-7 (but at most 10) digits
E Uppercase [E] character
[ + | - ] According to sign of exponent
<exponent> Two-digit decimal exponent
If DecPlaces is present, a fixed-point decimal string is written. If DecPlaces is larger than 11, it's assumed to be 11. The format of the fixed-point string follows:
[ <blanks> ] [ - ] <digits> [ . <decimals> ]
The following table lists the components of the fixed-point string.
Component Meaning
[ <blanks> ] Blanks to satisfy MinWidth
[ - ] If OutExpr is negative
<digits> At least one digit, but no leading zeros
[ . <decimals> ] Decimals if DecPlaces > 0
Write with one of the string-type values:
If MinWidth is omitted, the string value of OutExpr is written to the file with no leading blanks. If MinWidth is specified, and its value is larger than the length of OutExpr, enough blanks are written before the decimal string to make the field width MinWidth.
Write with a packed string-type value:
If OutExpr is of packed string type, the effect is the same as writing a string whose length is the number of elements in the packed string type.
Write with one of the Boolean type values:
If OutExpr is of type Boolean, the effect is the same as writing the strings True or False, depending on the value of OutExpr.
Note
When using Write the file must be open for output. |