如何使用函数中的值在innosetup中添加注册表项.我想在注册表中将IsServer的值设置为InstallAsServer的返回值
[Code]
[Registry]
Root: HKLM; Subkey: "Software\company\product\Settings"; ValueType: string; ValueName: "IsServer"; ValueData: {code:InstallAsServer}
var
Page: TInputOptionWizardPage;
IsServer: Boolean;
procedure InitializeWizard;
begin
Page := CreateInputOptionPage(wpWelcome,
'Install Type', 'Select Install Type',
'Please select Installation type; If Server click Server else Client',
True, False);
// Add items
Page.Add('Install as Server');
Page.Add('Install as Client');
// Set initial values (optional)
Page.Values[0] := True;
Page.Values[1] := False;
IsServer := Page.Values[0];
end;
function InstallAsServer(emppararm: string): string; //emppararm not used just for syntax
begin
if (IsServer=False) then
begin
result:= '0';
end
else
begin
result:= '1';
end
end;
Run Code Online (Sandbox Code Playgroud)
但即使我在页面中选择服务器或客户端,我总是将值设置为1
这是因为您IsServer只在向导表单初始化时分配变量的值.您需要从InstallAsServer函数中理想地读取实际值,因此您甚至可以删除IsServer变量.您可以将代码简化为以下内容:
[Registry]
Root: HKLM; Subkey: "Software\company\product\Settings"; ValueType: string; ValueName: "IsServer"; ValueData: {code:InstallAsServer}
[Code]
var
Page: TInputOptionWizardPage;
procedure InitializeWizard;
begin
Page := CreateInputOptionPage(wpWelcome, 'Install Type', 'Select Install Type',
'Please select Installation type; If Server click Server else Client', True,
False);
// add items
Page.Add('Install as Server');
Page.Add('Install as Client');
// set initial values (optional)
Page.Values[0] := True;
Page.Values[1] := False;
end;
function InstallAsServer(Value: string): string;
begin
// read the actual value directly from the Page
if not Page.Values[0] then
Result := '0'
else
Result := '1';
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10053 次 |
| 最近记录: |