The AssignFile procedure assigns a value to FileHandle for a FileName in preparation for reading or writing to that file.
Takes a text file variable type as the handle. The file is treated as a textfile when opened.
If the file name is an empty string, then file access is made to the console standard input and output streams.
Takes a binary file variable type as the handle. The file is treated as a binary file.
In both cases, when the file is opened by Append, Reset or ReWrite, it is assumed to be in the current directory.
|The FileHandle must no be confused with the file handle used for the low level file handling routines such as FileOpen and FileRead.|
|Append||Open a text file to allow appending of text to the end|
|AssignPrn||Treats the printer as a text file - an easy way of printing text|
|File||Defines a typed or untyped file|
|Reset||Open a text file for reading, or binary file for read/write|
|ReWrite||Open a text or binary file for write access|
|TextFile||Declares a file type for storing lines of text|
| Download this web site as a Windows program.
|Example code : Write to a text file, and then read back its contents|
myFile : TextFile;
text : string;
// Try to open the Test.txt file for writing to
// Write a couple of well known words to this file
// Close the file
// Reopen the file for reading
// Display the file contents
while not Eof(myFile) do
// Close the file for the last time
|Show full unit code|