Search code examples
inno-setuppascalscript

Inno Setup | Pascal: read out SelectedValueIndex, which changes a variable value


after trying for two days I finally decided to ask my first question here on Stackoverflow.

I have some experience programming in C#, but can't get my head around simple tasks in Pascal. Like the title says, i simply want to read out the currently selected radio button, which should change another variable's name.

The variable determines where the file unpacks on my pc.

Note: I am already able to read out my 'VersionNumber' variable, however it doesn't contain my selected element!

[Code]
var 
  Page1: TInputOptionWizardPage;
  SetupString21:string;
  SetupString22:string;
  SetupBool21:Boolean;
  SetupBool22:Boolean;
  VersionNumber:string;

procedure InitializeWizard;
begin
  SetupString21 := '2021'
  SetupString22 := '2022'
  VersionNumber := SetupString21

  Page1:= CreateInputOptionPage(1, 'Select a version', 'Help text', 'Second help text', True, False);

  //add items
  Page1.Add(SetupString21);
  Page1.Add(SetupString22);

  //set initial values (optional)
  Page1.Values[0] := True;

  //read values into variables
  SetupBool21 := Page1.Values[0]
  SetupBool22 := Page1.Values[1]

  if WizardForm.TypesCombo.SelectedValueIndex = SetupString22 then VersionNumber := SetupString22;
end;

function GetParams(Value: string): string;
begin  
  Result := VersionNumber;
end;

Solution

  • You didn't give us any context. Though from the signature and name of the GetParams function, I'll make a guess that it is an implementation of a scripted constant for a [Run] section.

    Then you probably want this:

    var
      SetupIndex21: Integer; // will be 0
      SetupIndex22: Integer; // will be 1
    
    procedure InitializeWizard;
    begin
      // ...
      SetupIndex21 := Page1.Add(SetupString21);
      SetupIndex22 := Page1.Add(SetupString22);
    
      // set initial value
      Page1.SelectedValueIndex := SetupIndex21;
    
      // ...
    end;
    
    function GetParams(Value: string): string;
    begin  
      if Page1.SelectedValueIndex = SetupIndex21 then Result := SetupString21
        else
      if Page1.SelectedValueIndex = SetupIndex22 then Result := SetupString22;
    end;