|
Writing Text Files |
Top Previous Next |
|
What is translated > File Input and Output > Writing Text Files Write and WriteLn write values to a TextFile or to the predefined Output file.
WRITE
Write outputs a value without adding a line ending.
Write(myFile, "Value: "); Write(myFile, value);
Without a file parameter, Output is used:
Write("Value: "); Write(value);
WRITELN
WriteLn writes a value and then adds a line ending.
WriteLn(myFile, "Finished"); WriteLn("Finished");
A parameterless WriteLn writes an empty line:
WriteLn();
FIELD WIDTH
Delphi output values can specify a minimum field width:
Write(myFile, value:10);
Depending on the translation pattern, this can be translated to:
Write(myFile, value, 10);
The value is right aligned and padded with spaces when it is shorter than the requested width.
Console output uses the corresponding overload without a TextFile parameter:
Write(value, 10);
DECIMAL PLACES
Real values can specify both a field width and a number of decimal places:
Write(myFile, value:10:2);
The corresponding C# runtime call is:
Write(myFile, value, 10, 2);
Console output uses:
Write(value, 10, 2);
Delphi real division must remain real division in C#.
For example:
Write(myFile, (double)i / 2, 5, 1);
MULTIPLE OUTPUT VALUES
The translator may split a Delphi Write or WriteLn statement into multiple C# calls.
For example:
WriteLn('':10, 'Path: ', Name);
can be translated to:
Write("", 10); Write("Path: "); WriteLn(Name);
All overloads without a TextFile parameter write to Output.
|
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |