SmartPascal
CloseFile
Procedure
Closes an open file System unit
 procedure CloseFile ( var FileHandle : TextFile ) ;
Description
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
Append Open a text file to allow appending of text to the end
AssignFile Assigns a file handle to a binary or text file
AssignPrn Treats the printer as a text file - an easy way of printing text
DeleteFile Delete a file specified by its file name
Erase Erase a file
RenameFile Rename a file or directory
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
 
Example code : Closing after write and read operations
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 the file in read only mode
  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