Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup ParseVersion is not callable from [Code]

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?

like image 370
Dan Avatar asked Dec 21 '20 22:12

Dan


2 Answers

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's both Pascal Script RemoveBackslash and Preprocessor RemoveBackslash.

like image 189
Martin Prikryl Avatar answered Oct 19 '22 00:10

Martin Prikryl


In the Change Log (for 6.1.x) it mentioned:

Support function GetFileVersion and ParseVersion have been renamed to GetVersionNumbersString and GetVersionComponents respectively. The old names are still supported, but it is recommended to update your scripts to the new names and the compiler will issue a warning if you don't.

So be wary of that when you upgrade. But as you rightly say, these are Inno Setup Preprocessor (ISPP) functions. With respects to the Pascal Script section there is nothing listed in the Support Function Reference.

Someone else might be able to shed more insight about this, or offer a workaround, but you might have to request the feature in the Info Setup forum.

like image 23
Andrew Truckle Avatar answered Oct 19 '22 01:10

Andrew Truckle