RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.IOResult Function

Returns the status of the last I/O operation performed.

Pascal
function IOResult: Integer;
C++
int IOResult();

IOResult returns the result of the last Delphi I/O routine when I/O-checking is off (that is, when using the {$I-} compiler option). If IOResult returns 0, the last I/O operation succeeded. Otherwise, IOResult returns an error code. 

If an I/O error occurs and I/O-checking is off, all subsequent I/O operations are ignored until the internal error flag is cleared. Calling IOResult clears the internal error flag. 

An alternative way to handle I/O errors is to use exception handling with the {$I+} compiler option. 

The following table lists all I/O errors, numbers, and descriptions.

Number  
Name  
Description  
100  
Disk read error  
Reported by Read on a typed file if you attempt to read past the end of the file.  
101  
Disk write error  
Reported by CloseFile, Write, WriteIn, or Flush if the disk becomes full.  
102  
File not assigned  
Reported by Reset, Rewrite, Append, Rename, or Erase if the file variable has not been assigned a name through a call to Assign or AssignFile.  
103  
File not open  
Reported by CloseFile, Read Write, Seek, Eof, FilePos, FileSize, Flush, BlockRead, or BlockWrite if the file is not open.  
104  
File not open for input  
Reported by Read, Readln, Eof, Eoln, SeekEof, or SeekEoln on a text file if the file is not open for input.  
105  
File not open for output  
Reported by Write or Writeln on a text file if you do not generate a Console application.  
106  
Invalid numeric format  
Reported by Read or Readln if a numeric value read from a text file does not conform to the proper numeric format.  

 

Delphi Examples: 

{
This example illustrates how to use IOResult to check the success of the Reset
method. If the call to Reset is successful, a message dialog displays the size
of the file that the user selects in an Open dialog. If the call to Reset fails,
a message warns the user that there was a file access error. To test the failure
part of this example, just misspell a file name in the open dialog.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  F: File of Byte;
begin
  if OpenDialog1.Execute then
  begin
    AssignFile(F, OpenDialog1.FileName);
    {$I-}
    Reset(F);
    {$I+}
    if IOResult = 0 then
    begin
      MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
        mtInformation, [mbOk], 0);
      CloseFile(F);
    end
    else
      MessageDlg('File access error', mtWarning, [mbOk], 0);
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!