Getting a file version number in the [Registry] se

2019-07-27 01:21发布

问题:

I am creating an installer for a visual studio project using inno setup. I am getting an error for

"Parameter ValueData has invalid value"

for this code:

[Code]
function GetVersion(AppVersion: String): String;
var
  Version: String;
  CharIndex: integer;
  c: char;
begin  
for CharIndex := 1 to Length(AppVersion) do begin
    c := AppVersion[CharIndex];
    if (c <> '.') then
    Version := Version + c;
end;
Result := Version;
end;

[Registry]
Root: HKCU; Subkey: "MyCompany\Product"; ValueType: DWORD ; ValueName: "Version" ;     ValueData: GetVersion({#MyAppVersion}); Flags: uninsdeletekey;

I have versioning like this "1.0.0.3, 1.0.0.4, etc". So this program removes . and concatenates all of them to form a number and should pass back to write to registry. So, I can check this registry value and uninstall or update the previous version. I heard someone saying inno would upgrade automcatically, but I create icons with their name with version number. Thanks in advance.

回答1:

The problem you are seeing is because to call a function as a parameter in the main sections of InnoSetup, you need to use the {code:} construct.
Here's an example that worked for me:

[Registry]
Root: HKCU; Subkey: "Software\MyCompany\Product"; ValueType: DWORD ; ValueName: "Version" ;     ValueData: {code:GetVersion|{#MyAppVersion}}; Flags: uninsdeletekey;


回答2:

As @Ken White said, your constant is "broken" which makes the entire string literal invalid. Even then, you ValueData is still just GetVersion(WhateverMyAppVersionIs) instead if the result of that function. For that, use a {code:} constant to call GetVersion.