Append
Belongs to : ProcedureDescription
The Append procedure opens a file given by FileHandle to allow subsequent writes to append to the end of the file.
You must use AssignFile to assign a file to the FileHandle before using Append.
This is often used when logging information – existing log data must be preserved, with the new log information appended to the end.
Use Write or WriteLn to write to the file after this Append is executed.
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
var myFile : TextFile; text : string; begin // Try to open the Test.txt file for writing to AssignFile(myFile, 'Test.txt'); ReWrite(myFile); // Write a couple of well known words to this file WriteLn(myFile, 'Hello'); WriteLn(myFile, 'World'); // Close the file CloseFile(myFile); // Reopen to append a final line to the file Append(myFile); // Write this final line WriteLn(myFile, 'Final line added'); // Close the file CloseFile(myFile); // Reopen the file for reading Reset(myFile); // Display the file contents while not Eof(myFile) do begin ReadLn(myFile, text); ShowMessage(text); end; // Close the file for the last time CloseFile(myFile); end; Show full unit code Hello World Final line added |