$I or $IOCHECKS : Input/Output checking

The {$I-} or {$IOCHECKS OFF} directive tells the compiler not to generate input/output checking code in the program. By default, the compiler does not generate this code, it must be switched on using the -Ci command-line switch.

When compiling using the -Ci compiler switch, the Free Pascal compiler inserts input/output checking code after every input/output call in the code. If an error occurred during input or output, then a run-time error will be generated. Use this switch to avoid this behaviour.

To check if something went wrong, the IOResult function can be used to see if everything went without problems.

Conversely, {$I+} will turn error-checking back on, until another directive is encountered which turns it off again.

The most common use for this switch is to check if the opening of a file went without problems, as in the following piece of code:

 assign (f,'file.txt');
 {$I-}
 rewrite (f);
 {$I+}
 if IOResult<>0 then
   begin
   Writeln ('Error opening file: "file.txt"');
   exit
   end;
See the IOResult function explanation in Reference guide for a detailed description of the possible errors that can occur when using input/output checking.