The macros ParseVersion
and RemoveBackslash
, for example, are both declared in ISPPBuiltins.iss
. If I attempt to call both from within [Code]:
function InitializeSetup: Boolean;
var
Major, Minor, Rev, Build: Integer;
begin
RemoveBackslash('123\');
ParseVersion('12345', Major, Minor, Rev, Build);
end;
RemoveBackslash
compiles fine, but adding ParseVersion
causes a compiler error:
Unknown identifier 'ParseVersion'"
When part of another macro declaration, ParseVersion
seems to compile fine, just not from [Code]
. Should I be able call it like that?
As @Andrew wrote already, the ParseVersion
(or actually since Inno Setup 6.1, the GetVersionComponents
) is a preprocessor function. So it has to be called using preprocessor directives and its results stored into preprocessor variables.
#define Major
#define Minor
#define Rev
#define Build
#expr GetVersionComponents("C:\path\MyProg.exe", Major, Minor, Rev, Build)
If you need to use the variables in the Pascal Script Code
, you again need to use preprocessor syntax. For example:
[Code]
function InitializeSetup: Boolean;
begin
MsgBox('Version is: {#Major}.{#Minor}.{#Rev}.{#Build}.', mbInformation, MB_OK);
Result := True;
end;
The above is true, if you really want to extract the version numbers on the compile-time. If you actually want to do it in the Code
section, i.e. on the install-time, you have to use Pascal Script support function GetVersionComponents
(yes, the same name, but a different language):
[Code]
function InitializeSetup: Boolean;
var
Major, Minor, Rev, Build: Word;
Msg: string;
begin
GetVersionComponents('C:\path\MyProg.exe', Major, Minor, Rev, Build);
Msg := Format('Version is: %d.%d.%d.%d', [Major, Minor, Rev, Build]);
MsgBox(Msg, mbInformation, MB_OK);
Result := True;
end;
The Pascal Script function GetVersionComponents
is available since Inno Setup 6.1 only.
The RemoveBackslash
works in both contexts, as there was both Pascal Script RemoveBackslash
and Preprocessor RemoveBackslash
(renamed to RemoveBackslashUnlessRoot
meanwhile).