Name

$IOChecks Compiler Directive

Syntax

{$I+}           // default
{$IOChecks On}  // default
{$I-}
{$IOChecks Off}

Scope

Local

Description

When $IOChecks is enabled, Delphi checks the results of all I/O functions and reports an I/O runtime error if a function fails. With $IOChecks disabled, you must call the IOResult function to learn whether an I/O operation succeeded.

Example

// Return True if the named file is a PostScript file,
// and False if the file does not exist or is not a PostScript file.
// A PostScript file starts with the characters '%!'.
function IsPostScript(const FileName: string): Boolean;
type
  TPair = array[0..1] of Char;
const
  PostScript: TPair = '%!';
var
  F: File of TPair;
  Pair: TPair;
begin
  AssignFile(F, FileName);
  FileMode := 0;
{$IOChecks Off}
  Reset(F);
  Read(F, Pair);
{$IOChecks On}
  Result := (IOResult = 0) and (Pair = PostScript);
  CloseFile(F);
end;

See Also

IOResult Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.