Closes an open file System unit
 procedure CloseFile(var FileHandle TextFile);
The CloseFile procedure closes an open file given by FileHandle.
The file must have been assigned, and opened with Append, Reset or ReWrite.
The file is closed, and the handle is made available for further assignment to files.
Related commands
AppendOpen a text file to allow appending of text to the end
AssignFileAssigns a file handle to a binary or text file
AssignPrnTreats the printer as a text file - an easy way of printing text
DeleteFileDelete a file specified by its file name
EraseErase a file
RenameFileRename a file or directory
ResetOpen a text file for reading, or binary file for read/write
ReWriteOpen a text or binary file for write access
TextFileDeclares a file type for storing lines of text
 Download this web site as a Windows program.

Example code : Closing after write and read operations
  myFile : TextFile;
  text   : string;

  // Try to open the Test.txt file for writing to
  AssignFile(myFile, 'Test.txt');

  // Write a couple of well known words to this file
  WriteLn(myFile, 'Hello');
  WriteLn(myFile, 'World');

  // Close the file

  // Reopen the file in read only mode

  // Display the file contents
  while not Eof(myFile) do
    ReadLn(myFile, text);

  // Close the file for the last time
Show full unit code
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page