SmartPascal
$IOChecks
Compiler Directive
When on, an IO operation error throws an exception
1   {$IOChecks Off}
2   {$IOChecks On}
Description
The $IOChecks compiler directive determines whether an exception is thrown when an IO operation encounters an error.
 
{$IOChecks On} default generates the EInOutError exception when an error occurs.
 
{$IOChecks Off} does not generate an exception. Instead, it is the responsiblity of the program to check the IO operation by using the IOResult routine.
Notes
The IOResult routine resets the IO error value to 0 when called.

$IOChecks is equivalent to $I.

This directive can be used multiple times within your code.

The default value is $IOChecks On
Related commands
$I Allows code in an include file to be incorporated into a Unit
IOResult Holds the return code of the last I/O operation
 
Example code : Try to create a directory twice
// 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
  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
  error : Integer;

begin
  // Try to create a new subdirectory in the current directory
  // Switch off I/O error checking
  {$IOChecks off}
  MkDir('TempDirectory');

  // Did the directory get created OK?
  error := IOResult;
  if error = 0
  then ShowMessage('Directory created OK')
  else ShowMessageFmt('Directory creation failed with error %d',[error]);

  // Try to create the directory again - this will fail!
  MkDir('TempDirectory');
  error := IOResult;
  if error = 0
  then ShowMessage('Directory created OK again')
  else ShowMessageFmt('Repeat creation failed with error %d',[error]);

  // Delete the directory to tidy up
  RmDir('TempDirectory');

  // Switch IO checking back on
  {$IOChecks on}
end;
 
end.
Hide full unit code
   Directory created OK
   Repeat creation failed with error 183