2014-11-03 32 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

相關問題