Search code examples
inno-setuppascalscript

"Unknown Identifier 'FileOpen'" when trying to detect locked file in Inno Setup code


I am attempting to use FileOpen in Inno Setup code, however the Inno Setup compiler keeps throwing me the following error.

Unknown Identifier 'FileOpen'

Here is a sample code:

function IsFileLocked(pathFile : string) : Boolean;
var
  hFile : integer;
begin
  Result := true;

  hFile := FileOpen(pathFile);
  if (0 <> hFile) then
    begin
      Result := false;

      { Since ISPP 1.2, Inno Setup automatically frees resources, so FileClose() is obsolete. }
      { http://www.jrsoftware.org/ispphelp/index.php?topic=fileclose }
    end;
end;

Unlike the FileClose method, FileOpen is not obsolete.

FileOpen

I did a Google search, but nothing turned up. I know that Inno Setup uses Pascal Script, not Pascal, but the FileOpen function is part of the Inno Setup Preprocessor: Functions.

Note: I upgraded to the latest version of the compiler (5.6.1a) this morning and the latest version of Inno Script Studio (2.3.0), same problem.

I do see the section Other Information > ISPPBuiltins.iss. I tried adding the line:

[Code]
#include <ISPPBuiltins.iss>

Adding the #include statement, generates the error

ISPPBuiltins.iss Line 1: Column 1:'BEGIN' expected.

Adding in ISPPBuiltins.iss to the project as a method to solve the FileOpen problem is meaningless, as opening the file in a text editor shows that 'FileOpen` does not exist in there. I do not see any embedded file. It would appear that the compiler does not like "; BEGIN..." in the file, but I digress. So much for that thought.

Thoughts on how to resolve my Unknown Identifier problem with FileOpen?


Solution

  • FileOpen is a preprocessor function. You cannot use it in Pascal Script code, which has its own function library.