2016-10-12 59 views
1

這是我在Inno Setup上使用的腳本。這是我的第一個劇本,請理解我是否問了一些明顯的問題。Inno Setup:CreateInputQueryPage沒有返回任何值

看來,變量ServerAddress從來沒有值,即使我填寫輸入字段。它看起來像Page.Values[0]總是返回一個空的結果。我的代碼有什麼問題?

正如你所看到的,我用一個testvar變量進行了測試,以排除它是一個變量範圍的問題,但事實並非如此。

[Code] 

var 
    Page: TInputQueryWizardPage; 
    ServerAddress: String; 
    testvar: String; 

procedure InitializeWizard(); 
begin 
    Page := CreateInputQueryPage(wpWelcome, 
    'Server Informations', '', 
    'Please specify the IP address, then click Next.'); 

    { Add items (False means it's not a password edit) } 
    Page.Add('IP Address:', False); 
    ServerAddress := Page.Values[0]; 
    testvar := 'testvalue'; 
end; 

procedure CurStepChanged(CurStep: TSetupStep); 
begin 
    if CurStep = ssPostInstall then begin 
    MsgBox(ExpandConstant('{app} '+testvar+' : '+ServerAddress),mbInformation,MB_OK); 
    SaveStringToFile(ExpandConstant('{app}')+'\config.txt', 'test'+ServerAddress, True); 
    end; 
end; 

回答

1

在甚至顯示嚮導窗口之前調用InitializeWizard event function(並結束)。

因此,一個值(用戶將在未來進入)很難在那個時候知道。只有在顯示自定義頁面後,您才必須閱讀該值。像在你的CurStepChanged(ssPostInstall)

procedure CurStepChanged(CurStep: TSetupStep); 
var 
    ServerAddress: string; 
begin 
    if CurStep = ssPostInstall then 
    begin 
    { This is the right time to read the value } 
    ServerAddress := Page.Values[0]; 

    SaveStringToFile(ExpandConstant('{app}') + '\config.txt', ServerAddress, True); 
    end; 
end; 
+0

它的作品,謝謝馬丁 – mark