2010-02-17 100 views
6

如果用戶在安裝過程中檢查相應的複選框,我想執行一些代碼。從閱讀幫助文件看來,使用該任務的唯一方法是將其與Files/Icons /等中的條目相關聯。部分。我真的很想將它與代碼部分的過程聯繫起來。這可以做到,如果是這樣,怎麼樣?通過Inno Setup中的任務啓動自定義代碼

回答

4

你做到這一點通過添加一個有複選框,並執行代碼,所有選中的複選框,當用戶點擊「下一步」,在該網頁上的自定義嚮導頁:

[Code] 
var 
    ActionPage: TInputOptionWizardPage; 

procedure InitializeWizard; 
begin 
    ActionPage := CreateInputOptionPage(wpReady, 
    'Optional Actions Test', 'Which actions should be performed?', 
    'Please select all optional actions you want to be performed, then click Next.', 
    False, False); 

    ActionPage.Add('Action 1'); 
    ActionPage.Add('Action 2'); 
    ActionPage.Add('Action 3'); 

    ActionPage.Values[0] := True; 
    ActionPage.Values[1] := False; 
    ActionPage.Values[2] := False; 
end; 

function NextButtonClick(CurPageID: Integer): Boolean; 
begin 
    Result := True; 
    if CurPageID = ActionPage.ID then begin 
    if ActionPage.Values[0] then 
     MsgBox('Action 1', mbInformation, MB_OK); 
    if ActionPage.Values[1] then 
     MsgBox('Action 2', mbInformation, MB_OK); 
    if ActionPage.Values[2] then 
     MsgBox('Action 3', mbInformation, MB_OK); 
    end; 
end; 

的複選框既可以成爲列表框中的標準控件或項目,有關詳細信息,請參閱Pascal腳本的Inno安裝文檔。

如果您希望根據是否選擇某個組件或任務來執行您的代碼,請改爲使用IsComponentSelected()IsTaskSelected()函數。

11

你不需要定義你自己的嚮導頁面。您可以將它們添加到其他任務頁面。

[Tasks] 
Name: associate; Description:"&Associate .ext files with this version of my program"; GroupDescription: "File association:" 

[Code] 
function NextButtonClick(CurPageID: Integer): Boolean; 
begin 
    Result := True; 
    if CurPageID = wpSelectTasks then 
    begin 
    if WizardForm.TasksList.Checked[1] then 
     MsgBox('First task has been checked.', mbInformation, MB_OK); 
    else 
     MsgBox('First task has NOT been checked.', mbInformation, MB_OK); 
    end; 
end; 

對於this post,信貸去TLama。