使用 InnoSetup 函数添加注册表键

4

我该如何在 InnoSetup 中添加一个注册表键,并使用函数返回值作为键值。我想将 InstallAsServer 的返回值设置为 IsServer 在注册表中的值。

[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;

但是即使我在页面上选择了服务器或客户端,我总是得到值为1。

非常感谢,它起作用了。(已回答结束)顺便问一下,我能问另一个问题吗?如何删除许可协议页面? - sjd
如果我删除许可文件,页面将不会显示。 - sjd
1个回答

6
那是因为你只在向导表单初始化时分配了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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接