gpt4 book ai didi

inno-setup - Inno 设置 : Add a Custom Input Field

转载 作者:行者123 更新时间:2023-12-03 14:35:02 26 4
gpt4 key购买 nike

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

我怎样才能做到这一点?我浏览了文档,谷歌搜索并没有太多结果!

谢谢大家的帮助

最佳答案

您可以在 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]脚本的部分,声明应该这样编写的 key :
Root: HKLM; Subkey: SOFTWARE\MyCompany\MyTool; ValueType: string; ValueName: MyValue; ValueData: {code:GetUserEnteredText}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue

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

关于inno-setup - Inno 设置 : Add a Custom Input Field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3212007/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com