Inno Setup运行时错误:“”不是有效的整数值

时间:2014-11-03 10:34:57

标签: inno-setup

我有以下代码:

Root: HKLM; Subkey: "Software\MyKey"; ValueType: dword; ValueName: "MyValue"; ValueData: "{reg:HKLM\SomeKey,SomeValue}"; Flags: createvalueifdoesntexist;

我运行安装程序时遇到上述错误。 {reg:HKLM \ SomeKey,SomeValue}上面是dword值。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您不能将{reg:...}常量用于REG_SZREG_EXPAND_SZ以外的值类型。这完全隐藏在DefaultValue参数描述中(我强调):

  

DefaultValue确定在指定的注册表中嵌入的字符串   值不存在,或不是字符串类型(REG_SZ或   REG_EXPAND_SZ)

对于您来说,这意味着您必须停止对REG_DWORD值类型注册表项使用{reg:...}常量。但是,您仍然可以编写一个{code:...}脚本函数来返回注册表项值:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Registry]                                                                                      
Root: HKLM; Subkey: "Software\MyKey"; ValueType: dword; ValueName: "MyValue"; ValueData: "{code:GetMyKeyValue}"; Flags: createvalueifdoesntexist;

[Code]
function GetMyKeyValue(Param: string): string;
var
  Value: DWORD;
begin
  // you should provide here a default integer value that will be used in case the key
  // value does not exist, otherwise you can end up with a similar error
  Result := '0';
  // query the registry key value and if it's found, return it
  if RegQueryDWordValue(HKLM, 'SomeKey', 'SomeValue', Value) then
    Result := IntToStr(Value);
end;