Description |
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.
|
|
Related commands |
AssignFile |
|
Assigns a file handle to a binary or text file |
TextFile |
|
Declares a file type for storing lines of text |
Write |
|
Write data to a binary or text file |
WriteLn |
|
Write a complete line of data to a text file |
|
|
|
Example code : Appending a line of text to an existing file |
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
|
|