Inno设置:添加自定义输入字段

Abs*_*Abs 16 inno-setup

我正在使用Inno Setup(令人惊叹!).我希望自定义安装程序,以便我可以以输入字段的形式接受来自用户的字符串,并可能向其添加消息.

我怎样才能做到这一点?我浏览了一下文档,谷歌搜索并没有多少出现!

谢谢大家的帮助

Tho*_*mar 35

您可以在InnoSetup中使用Pascal脚本来为安装程序创建新页面.这些页面可以集成到正常的安装流程中.这在InnoSetup 文档中有详细记录(谷歌搜索也应该提供样本).Program Files\InnoSetup中的Samples文件夹也有一些代码示例.

前一段时间,有一个名为InnoSetup表单设计器的软件,它允许您直观地设计页面.链接仍然存在,但在页面上我找不到下载.也许如果你环顾四周就可以找到它?

编辑
这是我制作过一次页面的示例.这是ISS文件的代码部分.[代码]

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;
Run Code Online (Sandbox Code Playgroud)

编辑2
要将用户输入的值写入注册表项,请创建一个新函数:

function GetUserEnteredText(param: String): String;
begin
  Result := Trim(tbTextBox.Text);
end;
Run Code Online (Sandbox Code Playgroud)

此函数只返回在文本框中输入的内容.请注意,该函数必须采用字符串参数 - 即使您忽略它!

[Registry]脚本部分中,声明应该像这样写的键:

Root: HKLM; Subkey: SOFTWARE\MyCompany\MyTool; ValueType: string; ValueName: MyValue; ValueData: {code:GetUserEnteredText}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue
Run Code Online (Sandbox Code Playgroud)

这将在HKLM\SOFTWARE\MyCompany\MyTool中创建一个名为"MyValue"的注册表值,其中包含用户在文本框中输入的内容.

  • omg,非常感谢!+1是不够的.对于那些看到这个问题的人,给他一些代表该死的!:) (3认同)

Dim*_* L. 8

以下是使用输入字段向 Inno Setup 安装程序添加自定义页面的较短代码:

var
  CustomQueryPage: TInputQueryWizardPage;

procedure AddCustomQueryPage();
begin
  CustomQueryPage := CreateInputQueryPage(
    wpWelcome,
    'Custom message',
    'Custom description',
    'Custom instructions');

  { Add items (False means it's not a password edit) }
  CustomQueryPage.Add('Custom Field:', False);
end;

procedure InitializeWizard();
begin
  AddCustomQueryPage();
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    { Read custom value }
    MsgBox('Custom Value = ' + CustomQueryPage.Values[0], mbInformation, MB_OK);
  end;
end;
Run Code Online (Sandbox Code Playgroud)