4

如何在 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;

但即使我在页面中选择服务器或客户端,我总是将值设置为 1

4

1 回答 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;
于 2013-03-15T09:01:10.030 回答