2010-07-09 210 views
14

我正在使用Inno Setup(其驚人的!)。我希望定製安裝程序,以便我可以接受來自用戶的輸入字段形式的字符串,並可能向其添加消息。Inno Setup:添加自定義輸入字段

我該怎麼做?我查看了文檔,谷歌搜索,並沒有多少出現!

感謝所有的幫助

+0

花了一段時間,我花了所有的假和斷開的鏈接來找到isfd208.exe(InnoSetup窗體設計器2.08)。正如Thorsten所說,原始鏈接已被破壞,但是[this one](http://uploaded.to/file/swq33y)在本評論發佈之日起生效。 (注意:它不能在我的Windows 7上運行,但在xp上運行) – Joe 2011-06-21 03:22:02

+0

來自Joe的鏈接也被中斷。 這是一個工作的:[http://www.cenadep.org/2012/02/09/innosetup-form-designer/](http://www.cenadep.org/2012/02/09/innosetup-表單設計師/) – 2013-07-05 08:20:23

回答

34

您可以使用InnoSetup帕斯卡爾腳本來創建用於安裝新的頁面。這些頁面可以集成到正常的安裝流程中。這在InnoSetup documentation內有很好的記錄(谷歌搜索也應該拿出樣品)。 Program Files \ InnoSetup中的Samples文件夾也有一些代碼示例。

前段時間,有一個名爲InnoSetup Form設計器的軟件,它允許您在視覺上設計頁面。鏈接仍然存在,但在頁面上我找不到下載。也許如果你環顧一下你可以找到它?

編輯
這是我製作一次的頁面示例。這是國際空間站文件的代碼段[代碼]

var 
    EnableFolderPage: Boolean; 
    lblBlobFileFolder: TLabel; 
    lblBlobFileWarning1: TLabel; 
    lblBlobFileWarning2: TLabel; 
    tbBlobFileFolder: TEdit; 
    btnBlobFileFolder: TButton; 



function GetBlobFolder(param: String): String; 
begin 
    Result := Trim(tbBlobFileFolder.Text); 
end; 


{ BlobFileForm_Activate } 
procedure BlobFileForm_Activate(Page: TWizardPage); 
var 
    s: string; 
begin 
    s := Trim(tbBlobFileFolder.Text); 
    if (s = '') then 
    begin 
    tbBlobFileFolder.Text := ExpandConstant('{sys}'); 
    end; 
end; 


{ BlobFileForm_NextButtonClick } 
function BlobFileForm_NextButtonClick(Page: TWizardPage): Boolean; 
var 
    s: string; 
begin 
    s := Trim(tbBlobFileFolder.Text); 
    if (s = '') then 
    begin 
    MsgBox(ExpandConstant('{cm:BlobFileForm_NoFolder}'), mbError, MB_OK); 
    Result := false; 
    end else 
    begin 
    if not DirExists(s) then 
    begin 
     MsgBox(ExpandConstant('{cm:BlobFileForm_DirDoesntExist}'), mbError, MB_OK); 
     Result := false; 
    end else 
    begin 
     Result := True; 
    end; 
    end; 
end; 

procedure btnBlobFileFolder_Click(sender: TObject); 
var 
    directory: string; 
begin 
    if BrowseForFolder('', directory, true) then 
    begin 
    tbBlobFileFolder.Text := directory; 
    end; 
end; 


{ BlobFileForm_CreatePage } 
function BlobFileForm_CreatePage(PreviousPageId: Integer): Integer; 
var 
    Page: TWizardPage; 
begin 
    Page := CreateCustomPage(
    PreviousPageId, 
    ExpandConstant('{cm:BlobFileForm_Caption}'), 
    ExpandConstant('{cm:BlobFileForm_Description}') 
); 

{ lblBlobFileFolder } 
    lblBlobFileFolder := TLabel.Create(Page); 
    with lblBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileFolder_Caption0}'); 
    Left := ScaleX(8); 
    Top := ScaleY(8); 
    Width := ScaleX(167); 
    Height := ScaleY(13); 
    end; 

    { lblBlobFileWarning1 } 
    lblBlobFileWarning1 := TLabel.Create(Page); 
    with lblBlobFileWarning1 do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning1_Caption0}'); 
    Left := ScaleX(8); 
    Top := ScaleY(80); 
    Width := ScaleX(50); 
    Height := ScaleY(13); 
    Font.Color := -16777208; 
    Font.Height := ScaleY(-11); 
    Font.Name := 'Tahoma'; 
    Font.Style := [fsBold]; 
    end; 

    { lblBlobFileWarning2 } 
    lblBlobFileWarning2 := TLabel.Create(Page); 
    with lblBlobFileWarning2 do 
    begin 
    Parent := Page.Surface; 
    Caption := 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption0}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption1}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption2}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption3}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption4}'); 
    Left := ScaleX(8); 
    Top := ScaleY(96); 
    Width := ScaleX(399); 
    Height := ScaleY(133); 
    AutoSize := False; 
    WordWrap := True; 
    end; 

    { tbBlobFileFolder } 
    tbBlobFileFolder := TEdit.Create(Page); 
    with tbBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Left := ScaleX(8); 
    Top := ScaleY(24); 
    Width := ScaleX(401); 
    Height := ScaleY(21); 
    TabOrder := 0; 
    end; 

    { btnBlobFileFolder } 
    btnBlobFileFolder := TButton.Create(Page); 
    with btnBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_btnBlobFileFolder_Caption0}'); 
    Left := ScaleX(320); 
    Top := ScaleY(48); 
    Width := ScaleX(91); 
    Height := ScaleY(23); 
    TabOrder := 1; 
    end; 

    with Page do 
    begin 
    OnActivate := @BlobFileForm_Activate; 
    OnNextButtonClick := @BlobFileForm_NextButtonClick; 
    end; 

    with btnBlobFileFolder do 
    begin 
    OnClick := @btnBlobFileFolder_Click; 
    end; 

    Result := Page.ID; 
end; 


procedure InitializeWizard(); 
begin 
    BlobFileForm_CreatePage(wpSelectDir); 
end; 

EDIT 2
要輸入用戶輸入的註冊表項值,創建一個新的功能:

function GetUserEnteredText(param: String): String; 
begin 
    Result := Trim(tbTextBox.Text); 
end; 

該功能僅返回在文本框中輸入的內容。請注意,該函數必須採用字符串參數 - 即使您忽略它!

在腳本的[Registry]部分,聲明應該這樣寫,關鍵:

Root: HKLM; Subkey: SOFTWARE\MyCompany\MyTool; ValueType: string; ValueName: MyValue; ValueData: {code:GetUserEnteredText}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue 

這將創建HKLM \ SOFTWARE名爲「myvalue的」註冊表值\ MyCompany的\ MyTool包含什麼用戶在文本框中輸入。

+1

謝謝你的例子,這真的有幫助!只是最後一件事,我如何捕獲用戶輸入的內容?然後我可以在寫入註冊表項時使用它作爲變量。 – Abs 2010-07-09 11:48:31

+0

查看我的編輯2 ... :-) – 2010-07-09 11:58:27

+3

omg,非常感謝! +1是不夠的。對於那些看到這個問題的人,請給他一些代表吧! :) – Abs 2010-07-09 12:18:08