通过Inno Setup中的任务启动自定义代码

mwo*_*e02 6 inno-setup

如果用户在安装期间检查相应的复选框,我想执行一些代码.从阅读帮助文件,看起来使用该任务的唯一方法是将其与文件/图标/等中的条目相关联.部分.我真的想将它与代码部分中的程序联系起来.可以这样做,如果是这样,怎么办?

Ste*_*ric 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;
Run Code Online (Sandbox Code Playgroud)

这篇文章归功于TLama .


mgh*_*hie 7

您可以通过添加一个带有复选框的自定义向导页面来实现这一点,并在用户单击该页面上的“下一步”时执行所有选定复选框的代码:

[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;
Run Code Online (Sandbox Code Playgroud)

复选框可以是标准控件或列表框中的项目,有关详细信息,请参阅有关 Pascal 脚本的 Inno Setup 文档。


如果您希望根据是否选择了某个组件或任务来执行代码,请改用WizardIsComponentSelected()WizardIsTaskSelected()函数。