Name

SetInOutRes Procedure

Syntax

procedure SetInOutRes(Code: Integer);

Description

The SetInOutRes procedure sets the I/O error code to Code. Calling IOResult returns this error code and then resets the code to zero.

Tips and Tricks

  • Each thread keeps its own I/O error code. Be sure to call SetInOutRes in the context of the correct thread.

  • Delphi reserves error codes 100-106 for its own I/O errors. (See IOResult for a description of these error codes.) For all other errors, use the standard Windows error codes.

  • Calling SetInOutRes does not raise the runtime error—it only stores the error code. If you want to report the I/O error, you must do that separately. See ErrorProc and RunError for examples of how to do this.

Example

// Implement Seek on a text file.
procedure TextSeek(var F: TextFile; Position: Integer);
var
  Handle: Integer;
  NewPosition: DWORD;
begin
  // A TextFile is actually a record whose first value is a handle.
  Handle := PInteger(@F)^;
  NewPosition := SetFilePointer(Handle, Position, nil, File_Begin);
  if NewPosition = $FFFFFFFF then
  begin
    SetInOutRes(GetLastError);
    ReportError(0); // zero means I/O error
  end;
end;

See Also

ErrorProc Variable, File Keyword, IOResult Function, RunError Procedure, TextFile Type

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.