Add registry key using function in innosetup

How to add registry key in innosetup with value from function. I want to set the IsServer value in the registry as the return value of 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; 

But I always get the value set as 1, even if I select the server or client on the page

+4
source share
1 answer

This is because you assign a value to your IsServer variable only when the wizard form is initialized. You will need to read the actual value ideally from your InstallAsServer function, so you can even remove the IsServer variable. You can simplify your code like this:

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

Source: https://habr.com/ru/post/1469442/


All Articles