2012-11-21 74 views
5

我想在自定義頁面中做一個自定義複選框(因爲它是一個頁面的安裝程序),只需要一個沒有對話框或任何東西的複選框,我試圖編譯的安裝程序是非常線性的簡單。如何在安裝期間爲可選文件添加CheckBox? (innosetup)

我想以這種方式在複選框上綁定「FILE3.EXE」:如果勾選複選框在DestDir中複製文件(FILE3.EXE),否則如果複選框沒有選中,請在安裝過程中跳過文件(FILE3.EXE) 。

這是我使用的代碼,很明顯的複選框代碼丟失,因爲我沒能做到這一點

[Files] 
Source: FILE1.EXE; DestDir: {app}; 
Source: FILE2.EXE; DestDir: {app}; 
Source: FILE3.EXE; DestDir: {app}; //OPTIONAL 

[Code] 
procedure ExitProcess(uExitCode: UINT); 
external '[email protected] stdcall'; 


var 
MainPage : TWizardPage; 
FolderToInstall : TEdit; 
InstallLocation : String; 


procedure CancelClick(Sender: TObject); 
begin 
if ExitSetupMsgBox then 
begin 
ExitProcess(0); 
end; 
end; 


procedure BrowseClick(Sender : TObject); 
var 
Dir : String; 

begin 
Dir := FolderToInstall.Text; 
if BrowseForFolder('Browse',Dir,false) then 
FolderToInstall.Text := Dir; 
WizardForm.DirEdit.Text := Dir; 
end; 


procedure InitializeWizard(); 
var 
LabelFolder : TLabel; 


MainPage := CreateCustomPage(wpWelcome,'',''); 
LabelFolder := TLabel.Create(MainPage); 
LabelFolder.Parent := WizardForm; 
LabelFolder.Top := 164; 
LabelFolder.Left := 6; 
LabelFolder.Caption := 'Directory:' 


FolderToInstall := TEdit.Create(MainPage); 
FolderToInstall.Parent := WizardForm; 
FolderToInstall.Top := 182; 
FolderToInstall.Left := 85; 
FolderToInstall.Width := 380; 
FolderToInstall.Text := WizardDirValue; 
FolderToInstall.ReadOnly := True; 
end; 
+1

你想有一個完整的自定義解決方案或你想使用已經內置功能於這個方法的? –

+0

我想在自定義頁面中做一個自定義複選框(因爲是一個頁面安裝程序),只需要一個沒有對話框或任何東西的複選框,我試圖編譯的安裝程序非常線性和簡單 – ApprenticeGeek

+1

然後創建一個複選框並使用[Files]節中的['Check'](http://jrsoftware.org/ishelp/topic_scriptcheck.htm#Check)參數來創建自定義函數。你想要那個複選框在哪裏? – TLama

回答

10

你需要做一個Check功能,將你的腳本[Code]部分返回複選框的狀態。像這樣的東西可能會做你想要什麼,但代碼腳本之前,我會糾正你在下面:

  • 使用TNEW ...類在那裏你能,所以你的情況使用的TNewEdit代替TEdit
  • 使用TWizardPage.SurfaceParent,如果你想在頁面(這裏我不知道在某個組件,如果這是你的意圖,只是指出了這一點:-)
  • 格式的代碼,它不需要如此平坦

在下面的例子中,我使用Check功能有條件稱爲InstallHelpFile安裝某個文件,在這種情況下MyProg.chmCheck函數工作簡單;當您將True返回給該函數時,文件將被處理,跳過時返回False。

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 
OutputDir=userdocs:Inno Setup Examples Output 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}" 
Source: "MyProg.chm"; DestDir: "{app}"; Check: InstallHelpFile; 

[Code] 
var 
    InstallHelpCheckBox: TNewCheckBox; 

procedure InitializeWizard; 
var 
    LabelFolder: TLabel; 
    MainPage: TWizardPage; 
    FolderToInstall: TNewEdit; 
begin 
    MainPage := CreateCustomPage(wpWelcome, '', ''); 
    LabelFolder := TLabel.Create(MainPage); 
    LabelFolder.Parent := WizardForm; 
    LabelFolder.Top := 164; 
    LabelFolder.Left := 6; 
    LabelFolder.Caption := 'Directory:' 

    FolderToInstall := TNewEdit.Create(MainPage); 
    FolderToInstall.Parent := MainPage.Surface; 
    FolderToInstall.Top := 182; 
    FolderToInstall.Left := 85; 
    FolderToInstall.Width := 380; 
    FolderToInstall.Text := WizardDirValue; 
    FolderToInstall.ReadOnly := True; 

    InstallHelpCheckBox := TNewCheckBox.Create(MainPage); 
    InstallHelpCheckBox.Parent := MainPage.Surface; 
    InstallHelpCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 8; 
    InstallHelpCheckBox.Left := FolderToInstall.Left; 
    InstallHelpCheckBox.Width := FolderToInstall.Width; 
    InstallHelpCheckBox.Caption := 'Install help file'; 
end; 

function InstallHelpFile: Boolean; 
begin 
    // here is the Check function used above; if you return True to this 
    // function, the file will be installed, when False, the file won't 
    // be installed 
    Result := InstallHelpCheckBox.Checked; 
end; 
+0

工作偉大! – ApprenticeGeek

10

您不必手動創建該的複選框。讓用戶選擇要安裝的標準方法是使用腳本文件的[Types][Components]部分。

查看位於iss安裝文件夾\ examples中的Componens.iss腳本。

; -- Components.iss -- 
; Demonstrates a components-based installation. 

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES! 

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 
DefaultGroupName=My Program 
UninstallDisplayIcon={app}\MyProg.exe 
OutputDir=userdocs:Inno Setup Examples Output 

[Types] 
Name: "full"; Description: "Full installation" 
Name: "compact"; Description: "Compact installation" 
Name: "custom"; Description: "Custom installation"; Flags: iscustom 

[Components] 
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed 
Name: "help"; Description: "Help File"; Types: full 
Name: "readme"; Description: "Readme File"; Types: full 
Name: "readme\en"; Description: "English"; Flags: exclusive 
Name: "readme\de"; Description: "German"; Flags: exclusive 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}"; Components: program 
Source: "MyProg.chm"; DestDir: "{app}"; Components: help 
Source: "Readme.txt"; DestDir: "{app}"; Components: readme\en; Flags: isreadme 
Source: "Readme-German.txt"; DestName: "Liesmich.txt"; DestDir: "{app}"; Components: readme\de; Flags: isreadme 

[Icons] 
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe" 

在運行時,安裝程​​序會顯示在嚮導中此對話框:

Components dialog

+2

@Globulorozzo你應該說明你的問題中的重要信息,希望每個人「在代碼中看到」對於誰試圖幫助你都不是很友善! – jachguate

+0

@Globulorozzo爲什麼不編輯你的問題?我們應該爲你做這個嗎? :( –

0
// Create: 
for i := 0 to g_SetupX_Count do begin 
    WizardForm.ComponentsList.AddCheckBox(g_SetupX_Name[i], '', 0, g_SetupX_Active[i], true, false, false, nil); 
    g_SetupX_CompListIndex[i] := nextPosi; 
    nextPosi := nextPosi + 1; 
end; 

// Evaluate: 
for i := 0 to g_SetupX_Count do begin 
    g_SetupX_Active[i] := WizardForm.ComponentsList.Checked[g_SetupX_CompListIndex[i]]; 
end; 
相關問題