2014-11-03 35 views
1

我有以下代码:Inno Setup的运行时错误:“”不是有效的整数值

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

和我,当我运行安装程序上述错误。 {reg:HKLM \ SomeKey,SomeValue}上面是一个双字值。我怎样才能解决这个问题?

+0

“SomeValue”键的类型是什么?它存在吗?另外,如果有可能这个键不存在,你必须为'{reg:}'常量提供一个默认值。当ValueType是dword时,你给'ValueData'的语句必须计算为整数。 – TLama 2014-11-03 10:38:50

+0

'SomeValue'是dword类型,确实存在。我有其他{reg:}常量,它检索字符串值,它运作良好。很奇怪... – sky 2014-11-03 11:53:51

+0

我说错了。在ValueType == dword的情况下,您传递给'ValueData'的语句可以评估为不是整数。它是为{REG_DWORD'键值返回一个'DefaultValue'值的'{reg:...}'常量。既然你没有提供默认值,它会返回一个空字符串。 – TLama 2014-11-03 12:59:18

回答

0

对于REG_SZREG_EXPAND_SZ以外的值类型,您不能使用{reg:...}常数。这是相当隐藏在DefaultValue参数说明(由我强调):

DefaultValue determines the string to embed if the specified registry value does not exist, or is not a string type (REG_SZ or REG_EXPAND_SZ).

对你来说意味着你必须停止使用{reg:...}常数REG_DWORD值类型的注册表项。但是,您仍然可以编写{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; 
+0

谢谢。但是,我希望我可以使用整数类型的{reg:...}常量......它使代码更清晰。 – sky 2014-11-03 13:16:27

+0

不客气!我懂了。但是此时你不能使用'{reg ...}'(['here'](https://github.com/jrsoftware/issrc/blob/is-5_5_5/Projects/Main.pas#L788)实际上只是查询字符串键值)。我不喜欢我在这里提供的{code ...}常量方式(但是这是目前唯一可以使用的脚本方式)。我宁愿将所有注册表创建条目移到'[Code]'部分,以将它们全部放在一个地方。但是您可以将其作为功能请求提交。 – TLama 2014-11-03 13:27:29

相关问题