Select 在InnoSetup动态组合框中,选中哪个项目并执行程序

Select 在InnoSetup动态组合框中,选中哪个项目并执行程序,select,dynamic,combobox,inno-setup,Select,Dynamic,Combobox,Inno Setup,在InnoSetup中,我想在完成的页面上显示一个组合框,其中显示已安装的组件。 您可以选择“无”或任何已安装的组件,并在单击“完成”时启动相关程序 这是我目前的代码: procedure CurPageChanged(CurPageID: Integer); var NewComboBox1: TNewComboBox; begin if (CurPageID = wpFinished) then begin NewComboBox1 := TNewComboBox.Create(

在InnoSetup中,我想在完成的页面上显示一个组合框,其中显示已安装的组件。 您可以选择“无”或任何已安装的组件,并在单击“完成”时启动相关程序

这是我目前的代码:

procedure CurPageChanged(CurPageID: Integer);
var
  NewComboBox1: TNewComboBox;
begin
  if (CurPageID = wpFinished) then begin
  NewComboBox1 := TNewComboBox.Create(WizardForm);
  with NewComboBox1 do begin
    Parent := WizardForm.FinishedPage;
    Left := ScaleX(256);
    Top := ScaleY(208);
    Width := ScaleX(145);
    Height := ScaleY(21);
    ItemIndex := 0;
    Style := csDropDownList;
    Items.Add('None');
    if IsComponentSelected('1') then
    Items.Add('Component 1');
    if IsComponentSelected('2') then
    Items.Add('Component 2');
    if IsComponentSelected('3') then
    Items.Add('Component 3');
    end;
  end;
end;
首先,我想将“无”设置为自动选择。当页面显示时。我查阅了许多Pascal论坛,但没有一个解决方案有效,比如NewComboBox1.ItemSelected=0(或类似的,记不清了…)。那么我该如何实现这一点呢

然后我不知道当点击Finish时如何启动程序。我想

function NextButtonClick
可能会有帮助,但设置中没有“下一步”按钮

可能还有一个问题,因为列表是根据选择的组件创建的,因此,如果未选择组件1,则项目1不是组件1,例如,组件2

我认为可以通过使这些项目不可见而不是完全不创建它们来解决这个问题

我查看了IS帮助文件中的支持类参考,但没有找到任何对我有帮助的内容


我期待着你的回答

由于缺少对组件绑定到的文件名和目标目录的访问,因此没有简单的方法来实现这一点。即使
TSetupComponentEntry
内部记录也不包含此信息,但即使包含此信息,您也无法访问它。因此,以下脚本使用其自己的单独数组,其中包含此任务所需的组件/文件链接:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Components]
Name: "program_32"; Description: "Program 32-bit"
Name: "program_x64"; Description: "Program 64-bit"
Name: "program_ia64"; Description: "Program IA 64-bit"

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Components: program_32
Source: "MyProg-x64.exe"; DestDir: "{app}"; Components: program_x64
Source: "MyProg-IA64.exe"; DestDir: "{app}"; Components: program_ia64

[Code]
type
  TFileData = record
    Component: string;
    Description: string;
    FileName: string;
    Parameters: string;
  end;  
var  
  ComponentCombo: TNewComboBox;
  ComponentArray: array of TFileData;
  SelectionArray: array of TFileData;

procedure InitializeWizard;
begin
  // this is a weakness of this solution - you need to fill the array
  // of components that can be added to the final combo box when they
  // are selected on component selection page. This is needed because
  // you can't get neither file name nor destination directory of the
  // file for the component from script. As first, set how many items
  // you want to add to your component array storage
  SetArrayLength(ComponentArray, 2);
  // the Component member must match to the "Name" parameter from the
  // [Components] section item since it's used in IsComponentSelected
  // function call
  ComponentArray[0].Component := 'program_32';
  // the Description member is the text displayed in the combo item
  ComponentArray[0].Description := 'Program 32-bit';
  // the FileName member is the name of the file including path. This
  // member may contain InnoSetup constants
  ComponentArray[0].FileName := '{app}/MyProg.exe';
  // the Parameters member contains execution parameters
  ComponentArray[0].Parameters := '-a';
  // this is the second item that can be added to the combo box, note
  // that the program_ia64 component is not added to this array, what
  // means, that it cannot be added to the "run" combo box. It's such
  // kind of a filter for components like help files etc.
  ComponentArray[1].Component := 'program_x64';
  ComponentArray[1].Description := 'Program 64-bit';
  ComponentArray[1].FileName := '{app}/MyProg-x64.exe';
  ComponentArray[1].Parameters := '-b';
end;

procedure CurPageChanged(CurPageID: Integer);
var
  I: Integer;
begin
  if (CurPageID = wpFinished) then
  begin
    ComponentCombo := TNewComboBox.Create(WizardForm);
    ComponentCombo.Parent := WizardForm.FinishedPage;
    ComponentCombo.Left := ScaleX(256);
    ComponentCombo.Top := ScaleY(208);
    ComponentCombo.Width := ScaleX(145);
    ComponentCombo.Height := ScaleY(21);
    ComponentCombo.Style := csDropDownList;

    ComponentCombo.Items.Add('None');
    for I := 0 to GetArrayLength(ComponentArray) - 1 do
      if IsComponentSelected(ComponentArray[I].Component) then
      begin
        ComponentCombo.Items.Add(ComponentArray[I].Description);
        SetArrayLength(SelectionArray, GetArrayLength(SelectionArray) + 1);
        SelectionArray[High(SelectionArray)] := ComponentArray[I];
      end;      
    ComponentCombo.ItemIndex := 0;
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  FileData: TFileData;
  ResultCode: Integer;
begin
  Result := True;
  if (CurPageID = wpFinished) and (ComponentCombo.ItemIndex > 0) then
  begin
    FileData := SelectionArray[ComponentCombo.ItemIndex - 1];
    Exec(ExpandConstant(FileData.FileName), FileData.Parameters, '', SW_SHOW,
      ewNoWait, ResultCode);
  end;
end;

由于缺少对组件绑定到的文件名和目标目录的访问,因此没有简单的方法来实现这一点。即使
TSetupComponentEntry
内部记录也不包含此信息,但即使包含此信息,您也无法访问它。因此,以下脚本使用其自己的单独数组,其中包含此任务所需的组件/文件链接:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Components]
Name: "program_32"; Description: "Program 32-bit"
Name: "program_x64"; Description: "Program 64-bit"
Name: "program_ia64"; Description: "Program IA 64-bit"

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Components: program_32
Source: "MyProg-x64.exe"; DestDir: "{app}"; Components: program_x64
Source: "MyProg-IA64.exe"; DestDir: "{app}"; Components: program_ia64

[Code]
type
  TFileData = record
    Component: string;
    Description: string;
    FileName: string;
    Parameters: string;
  end;  
var  
  ComponentCombo: TNewComboBox;
  ComponentArray: array of TFileData;
  SelectionArray: array of TFileData;

procedure InitializeWizard;
begin
  // this is a weakness of this solution - you need to fill the array
  // of components that can be added to the final combo box when they
  // are selected on component selection page. This is needed because
  // you can't get neither file name nor destination directory of the
  // file for the component from script. As first, set how many items
  // you want to add to your component array storage
  SetArrayLength(ComponentArray, 2);
  // the Component member must match to the "Name" parameter from the
  // [Components] section item since it's used in IsComponentSelected
  // function call
  ComponentArray[0].Component := 'program_32';
  // the Description member is the text displayed in the combo item
  ComponentArray[0].Description := 'Program 32-bit';
  // the FileName member is the name of the file including path. This
  // member may contain InnoSetup constants
  ComponentArray[0].FileName := '{app}/MyProg.exe';
  // the Parameters member contains execution parameters
  ComponentArray[0].Parameters := '-a';
  // this is the second item that can be added to the combo box, note
  // that the program_ia64 component is not added to this array, what
  // means, that it cannot be added to the "run" combo box. It's such
  // kind of a filter for components like help files etc.
  ComponentArray[1].Component := 'program_x64';
  ComponentArray[1].Description := 'Program 64-bit';
  ComponentArray[1].FileName := '{app}/MyProg-x64.exe';
  ComponentArray[1].Parameters := '-b';
end;

procedure CurPageChanged(CurPageID: Integer);
var
  I: Integer;
begin
  if (CurPageID = wpFinished) then
  begin
    ComponentCombo := TNewComboBox.Create(WizardForm);
    ComponentCombo.Parent := WizardForm.FinishedPage;
    ComponentCombo.Left := ScaleX(256);
    ComponentCombo.Top := ScaleY(208);
    ComponentCombo.Width := ScaleX(145);
    ComponentCombo.Height := ScaleY(21);
    ComponentCombo.Style := csDropDownList;

    ComponentCombo.Items.Add('None');
    for I := 0 to GetArrayLength(ComponentArray) - 1 do
      if IsComponentSelected(ComponentArray[I].Component) then
      begin
        ComponentCombo.Items.Add(ComponentArray[I].Description);
        SetArrayLength(SelectionArray, GetArrayLength(SelectionArray) + 1);
        SelectionArray[High(SelectionArray)] := ComponentArray[I];
      end;      
    ComponentCombo.ItemIndex := 0;
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  FileData: TFileData;
  ResultCode: Integer;
begin
  Result := True;
  if (CurPageID = wpFinished) and (ComponentCombo.ItemIndex > 0) then
  begin
    FileData := SelectionArray[ComponentCombo.ItemIndex - 1];
    Exec(ExpandConstant(FileData.FileName), FileData.Parameters, '', SW_SHOW,
      ewNoWait, ResultCode);
  end;
end;

您设置
项目索引的时间太早了。您需要输入组合框,然后设置项目索引。设置
ItemIndex
在当前代码中以静默方式失败,因为还没有索引为0的项目。好的,我在末尾设置了ItemIndex,现在没有自动显示的项目!谢谢你!现在我只需要知道如何获取所选项目的值…您不会获取值,您想打开组合框中所选组件后面的文件,是吗?您应该在
InitializeWizard()
事件函数中添加控件。然后,您可以(清除并)添加所需的任何项目,并在
CurPageChanged(wpfished)
中选择默认值。是的,每个组件都安装了.exe文件。通过组合框,我想让用户选择启动一个已安装的.exe文件。您过早地设置了
ItemIndex
。您需要输入组合框,然后设置项目索引。设置
ItemIndex
在当前代码中以静默方式失败,因为还没有索引为0的项目。好的,我在末尾设置了ItemIndex,现在没有自动显示的项目!谢谢你!现在我只需要知道如何获取所选项目的值…您不会获取值,您想打开组合框中所选组件后面的文件,是吗?您应该在
InitializeWizard()
事件函数中添加控件。然后,您可以(清除并)添加所需的任何项目,并在
CurPageChanged(wpfished)
中选择默认值。是的,每个组件都安装了.exe文件。通过组合框,我想让用户选择启动一个已安装的.exe-files.Wow!谢谢你的努力!我只是想尝试一下,但出现了一个错误:第185行:第24列:未知标识符“高”。。。。在“SelectionArray[High(SelectionArray)]:=ComponentArray[I];”行中,不客气!我已经在Unicode InnoSetup 5.5.1中测试了这个脚本,现在应该是最新的版本,所以可能它不在一些旧版本中。甚至还有一个更新的版本,5.5.2,但我有一个非Unicode版本。。。我安装的是Unicode,然后它工作了!再次感谢你!哦,我的最新版本晚了3天:-)我现在必须升级了!如果
High(x)
不可用,可以将其替换为
GetArrayLength(x)-1
。(以防万一有人想在不切换到Unicode的情况下使用此代码。)哇!谢谢你的努力!我只是想尝试一下,但出现了一个错误:第185行:第24列:未知标识符“高”。。。。在“SelectionArray[High(SelectionArray)]:=ComponentArray[I];”行中,不客气!我已经在Unicode InnoSetup 5.5.1中测试了这个脚本,现在应该是最新的版本,所以可能它不在一些旧版本中。甚至还有一个更新的版本,5.5.2,但我有一个非Unicode版本。。。我安装的是Unicode,然后它工作了!再次感谢你!哦,我的最新版本晚了3天:-)我现在必须升级了!如果
High(x)
不可用,可以将其替换为
GetArrayLength(x)-1
。(以防有人想在不切换到Unicode的情况下使用此代码。)