Name
IOResult Function
Syntax
function IOResult: Integer;
Description
Delphi has two ways to report an I/O
error: runtime errors or the IOResult function. By
default, Delphi reports I/O errors as runtime errors, and the
SysUtils unit maps runtime errors to exceptions.
If you use the $I- or $IOChecks
Off directives to turn off I/O runtime errors,
Delphi returns the status of input and output operations in the
IOResult function. It is the programmer’s
responsibility to call IOResult to test the
success or failure of each I/O procedure or function
call.
IOResult returns zero for success or an error code
for failure. The error code might be a Windows error code, or one of
the following Delphi error codes.
|
Error Number |
Description |
|
100 |
Read past end of file. |
|
101 |
Disk is full. |
|
102 |
|
|
103 |
The file is closed. |
|
104 |
File not open for input. |
|
105 |
File not open for output. |
|
106 |
Incorrectly formatted input for |
After you call IOResult, the I/O result code is
reset to zero. IOResult is a real function.
Tips and Tricks
Each thread keeps its own I/O result code, so be sure to call
IOResultin the context of the correct thread.It is the programmer’s responsibility to call
IOResultafter each I/O routine. If you don’t checkIOResult, a subsequent I/O call can overwrite the old error code with a new one.The
SysUtilsunit maps I/O errors to theEInOutErrorexception. This exception class maps only a few I/O error codes to strings. In a real application, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access