對於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