DelphiBasics
IOResult
Function
Holds the return code of the last I/O operation System unit
 function IOResult : Integer;
Description
The IOResult function retrieves the result of the last I/O (file input/output) operation.
 
This number is zero if the operation succeeded, or a positive number if it failed.
 
Use IOResult when you have disabled the default Delphi IO error trapping. When $IOChecks is On, Delphi raises exceptions for the errors. When Off, Delphi does not raise exceptions, requiring the code to inspect IOResult.
Notes
Warning : retrieval of the IO result is a one-off activity - the retrieval resets the value to 0.
Related commands
$IOChecks When on, an IO operation error throws an exception
GetLastError Gives the error code of the last failing Windows API call
 Download this web site as a Windows program.

Development Boards at very low prices with free postage.


 
Example code : Create a directory twice, catching the error code
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;  // Save the return code
  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;
Show full unit code
   Directory created OK
   Repeat creation failed with error 183
 
 
Delphi Programming Neil Moffatt 2002 - 2014. All rights reserved.  |  Contact the author  |  Home Page