对于REG_SZ
或REG_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;
“SomeValue”键的类型是什么?它存在吗?另外,如果有可能这个键不存在,你必须为'{reg:}'常量提供一个默认值。当ValueType是dword时,你给'ValueData'的语句必须计算为整数。 – TLama 2014-11-03 10:38:50
'SomeValue'是dword类型,确实存在。我有其他{reg:}常量,它检索字符串值,它运作良好。很奇怪... – sky 2014-11-03 11:53:51
我说错了。在ValueType == dword的情况下,您传递给'ValueData'的语句可以评估为不是整数。它是为{REG_DWORD'键值返回一个'DefaultValue'值的'{reg:...}'常量。既然你没有提供默认值,它会返回一个空字符串。 – TLama 2014-11-03 12:59:18