2010-02-17 73 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。