【问题标题】:Inno Setup: Add a Custom Input FieldInno Setup:添加自定义输入字段
【发布时间】:2011-03-13 19:47:24
【问题描述】:

我正在使用 Inno Setup(它太棒了!)。我希望自定义安装程序,以便我可以以输入字段的形式接受来自用户的字符串,并可能向其中添加一条消息。

我该怎么做?我浏览了文档,谷歌搜索并没有找到太多内容!

感谢大家的帮助

【问题讨论】:

  • 我花了一段时间浏览所有虚假和损坏的链接以找到 isfd208.exe (InnoSetup Form Designer 2.08)。正如 Thorsten 所说,原始链接已损坏,但 this one 在此评论之日有效。 (注意:它不能在我的 Windows 7 上运行,但可以在 xp 上运行)
  • Joe 的链接也断开了。这是一个有效的:http://www.cenadep.org/2012/02/09/innosetup-form-designer/
  • 这两个链接现在断开了。

标签: inno-setup


【解决方案1】:

您可以在 InnoSetup 中使用 Pascal 脚本为安装程序创建新页面。这些页面可以集成到正常的安装流程中。这在 InnoSetup documentation 中有很好的记录(谷歌搜索也应该提供示例)。 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;

编辑 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\MyCompany\MyTool 中创建一个名为“MyValue”的注册表值,其中包含用户在文本框中输入的内容。

【讨论】:

  • 谢谢你的例子,这真的很有帮助!最后一件事,我如何捕获用户输入的内容?然后,我可以在写入注册表项时将其用作变量。
  • 天哪,非常感谢! +1 还不够。对于那些看到这个问题的人,给他一些代表该死的! :)
  • InnoSetup 表单设计器已停产。它不再更新,您将无法从其原始开发者那里获得它......
  • 听到这个消息很难过。尤其是无法从它的原始开发者那里获得它的部分让我希望他没有发生任何不好的事情......它曾经是一个不错的软件。
  • 此代码已过时。有关最新解决方案,请参阅 answer by @DimaL
【解决方案2】:

以下是使用输入字段向 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多