SmartPascal
Flush
Procedure
Flushes buffered text file data to the file System unit
 procedure Flush ( var FileHandle : TextFile ) ;
Description
The Flush procedure flushes unwritten text file data to disk.
 
The same effect can be achieved by closing the file. In fact, this is more likely to be effective, since Flush simply passes the flush request to the Operating System, which may in turn be doing its own buffering, and possibly caching.
Related commands
AssignFile Assigns a file handle to a binary or text file
CloseFile Closes an open file
File Defines a typed or untyped file
TextFile Declares a file type for storing lines of text
 
Example code : Flushing after writing lines to a file
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

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');
  Flush(myFile);

  // 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;
 
end.
Hide full unit code
   Hello
   World