Getting a file version number in the [Registry] section

六眼飞鱼酱① 提交于 2019-12-11 13:55:58

问题


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.



来源:https://stackoverflow.com/questions/7667820/getting-a-file-version-number-in-the-registry-section

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!