我已经在TInputQueryWizardPage
页面中有一个combobox
,但问题是我不知道如何在第一次运行写入后从注册表中检索所选值。
我的组合框代码是:
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, 'SoftwareRiskValue',
'ReportProdAuthType', ExpandConstant('{code:GetAuthCombo}'));
end;
如果我从combobox
中选择第二个选项 Windows 身份验证,我希望在第二次运行安装程序时具有与默认值相同的值(Windows 身份验证)。
替换这个:
AuthComboBox.ItemIndex := 0;
跟:
var
S: string;
begin
{ ... }
if RegQueryStringValue(HKLM, 'SoftwareRiskValue', '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: "SoftwareRiskValue"; ValueType: string;
ValueName: "ReportProdAuthType"; ValueData: "{code:GetAuthCombo}"
或者,如果你想使用 Pascal 脚本,直接使用GetAuthCombo
:
if (CurStep=ssPostInstall) then
begin
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SoftwareRiskValue',
'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, 'SoftwareRiskValue', 'ReportProdAuthType', S);
end;
end;