2012-10-11 80 views
2

在InnoSetup中,我想顯示已完成頁面上的組合框,它顯示已安裝的組件。 您可以選擇「無」或任何已安裝的組件,並在點擊完成時啓動相關程序。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(或類似的,不記得沒錯......)。那麼我如何實現這一目標呢?

然後我不知道如何使程序啓動時點擊完成。我以爲

function NextButtonClick 

可能會幫助,但沒有下一步按鈕在設置工作。

也許還有一個問題,因爲根據選擇了哪些組件創建了列表,所以如果沒有選擇組件1但未選擇組件2,則項目1不是組件1。

我以爲人們可以通過使物品不可見而不是根本不創造它來解決這個問題。

我查看了IS幫助文件中的支持類參考,但沒有找到任何有助於我的內容。

我期待您的回答!

+0

您正在設置'ItemIndex'太早。您需要提供組合框,然後設置項目索引。因爲沒有索引爲0的項目,因此在當前代碼中默認設置ItemIndex失敗。 – TLama

+0

好吧,我在最後設置ItemIndex,現在None會自動顯示!感謝你!現在我只需要知道如何獲得所選項目的值... – user1662035

+0

您不打算獲得*值*,您想要打開在組合框中選擇的組件後面的文件* don你呢? – TLama

回答

0

由於缺少訪問組件綁定到的文件名和目標目錄的缺少訪問權限,因此沒有簡單的方法。即使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; 
+0

哇!感謝您的努力!我只是想嘗試它,但得到一個錯誤: 行185: 列24: 未知標識符'高'....它在行「SelectionArray [High(SelectionArray)]:= ComponentArray [I];」 – user1662035

+0

不客氣!我已經在Unicode InnoSetup 5.5.1中測試過這個腳本,此時最新的版本應該是什麼,所以也許它不在一些老版本中。 – TLama

+1

甚至有更新的版本,5.5.2,但我有非Unicode版本...我安裝IS-Unicode,然後它的工作!再次感謝你! – user1662035