创新设置:添加自定义输入字段 [英] Inno Setup: Add a Custom Input Field

查看:56
本文介绍了创新设置:添加自定义输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making use of Inno Setup (its amazing!). I was hoping to customise the installer so that I can accept a string from the user in the form of an input field and maybe add a message to it.

我该怎么做?我通过文档,谷歌搜索进行了浏览,但并没有看到太多内容!

How can I do this? I had a look through the docs, google search and not much came up!

感谢所有帮助

推荐答案

您可以在InnoSetup中使用Pascal脚本来为安装程序创建新页面.这些页面可以集成到常规安装流程中. InnoSetup 文档中对此文档进行了详细记录(Google搜索也应提供示例).另外,Program Files \ InnoSetup中的Samples文件夹也包含一些代码示例.

You can use Pascal scripting in InnoSetup to create new pages for the installer. These pages can be integrated into the normal installation flow. This is well documented within the InnoSetup documentation (Google search should also come up with samples). Also the Samples folder within your Program Files\InnoSetup has some code examples.

前一段时间,有一个名为InnoSetup Form designer的软件,它使您可以直观地设计页面.链接仍然存在,但是在页面上我找不到下载.也许如果您四处看看可以找到它吗?

Some time ago, there was a software called InnoSetup Form designer, which allowed you to visually design the page. The link is still there, but on the page I could not find the download. Maybe if you look around a bit you can find it?

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

EDIT
This is a sample for a page I made once. This is the code section of the ISS file.[Code]

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
要将用户输入的值写入注册表项,请创建一个新函数:

EDIT 2
To write the value the user entered to a registry key, create a new function:

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

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

This function simply returns what was entered in the text box. Please note that the function must take a string parameter - even though you ignore it!

在脚本的[Registry]部分中,声明应这样写的密钥:

In the [Registry] section of your script, declare the key that should be written like that:

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

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

This creates a registry value named "MyValue" in HKLM\SOFTWARE\MyCompany\MyTool that contains what the user entered in the text box.

这篇关于创新设置:添加自定义输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆