Flush

From Delphi Pascal wiki
Jump to navigation Jump to search

Flushes the buffer of a text file open for output.

Declaration
procedure Flush(var F: Text);
Target
Windows, Real, Protected
Remarks
F is a text file variable.
When a text file has been opened for output using Rewrite or Append, a call to Flush will empty the file's buffer. This guarantees that all characters written to the file at that time have actually been written to the external file. Flush has no effect on files opened for input.
With {$I-}, IOResult returns 0 if the operation was successful; otherwise, it returns a nonzero error code.


Sample Code

{Flush.PAS}
{Sample code for the Flush procedure.}

{ For Windows: }
{ uses WinDos, WinCrt; }

uses Dos;
procedure ReportError(s : String);
  { Redirect output to the DOS standard
   error handle and emit an error message,
   then halt.
   The file "output" must be flushed before
   its handle is changed, or some earlier
   output may appear with the error
   message.}
  begin
  Flush(output); { Must flush current output}
  { Redirect output to standard error handle}
  TextRec(output).handle := 2; { For Windows: TTextRec }
  Writeln(s);
  Halt(1);
  end;
begin
ReportError('An error occurred');
end.