inno-setup - 从注册表中检索组合框的值,并通过覆盖安装程序第二次运行的默认值来填充它
问题描述
我已经有combobox
一个TInputQueryWizardPage
页面,但问题是我不知道如何在第一次运行写入后从注册表中检索选定的值。
我的组合框代码是:
AuthComboBox := TNewComboBox.Create(ReportPage);
AuthComboBox.Parent := ReportPage.Edits[1].Parent;
AuthComboBox.Left := ReportPage.Edits[1].Left;
AuthComboBox.Top := ReportPage.Edits[1].Top;
AuthComboBox.Width := ReportPage.Edits[1].Width;
AuthComboBox.Height := ReportPage.Edits[1].Height;
AuthComboBox.TabOrder := ReportPage.Edits[1].TabOrder;
AuthComboBox.Items.Add('Password Authentication');
AuthComboBox.Items.Add('Windows Authentication');
AuthComboBox.ItemIndex := 0;
{ Hide the original edit box }
ReportPage.PromptLabels[1].FocusControl := AuthComboBox;
ReportPage.Edits[1].Visible := False;
AuthComboBox.OnChange := @ComboBoxChange;
背后的价值观AuthComboBox.Items.Add
是:
function GetAuthCombo(Param: String): String;
begin
case AuthComboBox.ItemIndex of
0: Result := 'False';
1: Result := 'True';
end;
end;
我使用以下代码将它们写入注册表:
if (CurStep=ssPostInstall) then
begin
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\RiskValue',
'ReportProdAuthType', ExpandConstant('{code:GetAuthCombo}'));
end;
如果我从中选择第二个选项 Windows 身份验证,combobox
那么当我第二次运行安装程序时,我希望现在具有与默认值相同的值(Windows 身份验证)。
解决方案
替换这个:
AuthComboBox.ItemIndex := 0;
和:
var
S: string;
begin
{ ... }
if RegQueryStringValue(HKLM, 'Software\RiskValue', 'ReportProdAuthType', S) and
SameText(S, 'True') then
begin
AuthComboBox.ItemIndex := 1;
end
else
begin
AuthComboBox.ItemIndex := 0;
end;
{ ... }
end;
此外,使用ExpandConstant
来获取注册表项的值是过度设计的。
从[Registry]
部分使用它(脚本常量的用途):
[Registry]
Root: HKLM; Subkey: "Software\RiskValue"; ValueType: string; \
ValueName: "ReportProdAuthType"; ValueData: "{code:GetAuthCombo}"
或者,如果你想使用 Pascal 脚本,GetAuthCombo
直接使用:
if (CurStep=ssPostInstall) then
begin
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\RiskValue',
'ReportProdAuthType', GetAuthCombo(''));
end;
然后,您甚至可以删除Param: String
,甚至GetAuthCombo
完全内联该函数,除非您在其他地方使用它。
var
S: string;
begin
{ ... }
if (CurStep=ssPostInstall) then
begin
case AuthComboBox.ItemIndex of
0: S := 'False';
1: S := 'True';
end;
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\RiskValue', 'ReportProdAuthType', S);
end;
end;
推荐阅读
- javascript - 如何使用反射。申请TS
- python - Python:AttributeError:'int'对象没有属性'isalpha'
- react-native - 是否可以对视频文件 blob 进行切片,然后在服务器端对其重新编码?
- java - noAdajacentDuplicates 使用堆栈
- android - 使用 Picasso android 无法通过 ImageView 中的 URL 加载图像
- unity3d - 按钮的统一动作如何附加到 AR 对象(ImageTarget)?
- pandas - 如何将 TF_IDF 矢量化器与自定义特征相结合
- php - 无法从数据库中获取下拉值
- json.net - 为什么 JSON 字符串不为空时 JSON 反序列化器返回空值?
- php - 如何从 Web 根目录外的 MULTIPLE 目录提供图像?