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 に答える