在Inno Setup的安装过程中,如何为可选文件添加复选框? [英] How can I add a check box for optional files during install in Inno Setup?
问题描述
我试图在我的自定义页面中创建一个自定义复选框(因为它是一页安装程序),只需要一个没有对话框或其他任何内容的复选框,我要编译的安装程序非常线性且简单.
I'm trying to make a custom checkbox in my custom page (because it's a one page installer), is needed only a checkbox without dialogs or anything, the installer that I'm trying to compile is very linear and simple.
我想以此方式将FILE3.EXE
绑定到复选框:如果选中了复选框,则将文件(FILE3.EXE
)复制到DestDir
中,否则,如果未选中复选框,则在安装过程中跳过文件(FILE3.EXE
).
I want to bind FILE3.EXE
on a checkbox in this way: if checkbox is checked copy the file (FILE3.EXE
) in DestDir
, otherwise if checkbox is unchecked skip the file (FILE3.EXE
) during installation.
这是我使用的代码,显然缺少复选框代码,因为我无法做到这一点
This is the code that I used, obviously the checkbox code is missing because I'm not able to do that
[Files]
Source: FILE1.EXE; DestDir: {app};
Source: FILE2.EXE; DestDir: {app};
Source: FILE3.EXE; DestDir: {app}; //OPTIONAL
[Code]
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess@kernel32.dll 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;
begin
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;
推荐答案
您需要进行 Check
函数,该函数将从 [Code]
脚本部分.这样的事情可能会满足您的要求,但是在编写代码脚本之前,我将在以下内容中对您进行纠正:
You need to make a Check
function which will return state of the check box from the [Code]
section of your script. Something like this might do what you want, but before the code script I would correct you in the following:
- 在可能的地方使用 TNew ... 类,因此在您的情况下使用
TEdit
- 如果希望拥有一个
Parent
,请使用TWizardPage.Surface
作为Parent
.页面上的某些组件(在这里我不确定这是否是您的意图,只是指出这一点:-) - 设置代码格式,不需要太平整
- use TNew... classes where you're able to, so in your case use
TNewEdit
instead ofTEdit
- use
TWizardPage.Surface
as aParent
if you want to have a certain component on the page (here I'm not sure if that's your intention, just pointing this out :-) - format your code, it doesn't need to be so flat
在以下示例中,我使用了 Check
函数,称为MyProg.chm
. Check
功能很简单;当您向函数返回True时,将处理文件,返回False时将跳过该文件.
In the following example I've used Check
function called InstallHelpFile
for conditional install of a certain file, in this case MyProg.chm
. The Check
function works simply; when you return True to the function, the file is processed, skipped is when you return 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;
这篇关于在Inno Setup的安装过程中,如何为可选文件添加复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!