Search code examples
inno-setuppascalscript

Inno Setup Run code according to setup type


I want to provide a couple of different installation types performing different operations to my installer: if "ApplicationServer" type is selected, only perform part of the code. If Client type is selected instead, only perform this part of the procedure.

I tried to include the 2 "blocks" of code within a function called

[Types]
Name: "application"; Description: "{cm:ApplicationServer}"
Name: "client"; Description: "{cm:Client}"

[CustomMessages]
ApplicationServer=Application Server:
Client=Client:
    

If first choice selected, I want to perform a specific code made of several procedures, constant, variables to run a sequence of SQL script, while if second is chosen I need to perform some other stuffs into the code area, like this:

[Code]

function ApplicationServer(blabla)
begin
  // <!This part only to run for ApplicationServer type!>
  // following constants and variables for the ADO Connection + SQL script run
  const
    myconstant1=blabla;
  var
    myvar1=blabla;    
  // here all the procedure to define and
  // manage an ADO Connection to run a sql script
  // procedure 1
  // procedure 2
end

function Client(blabla)
begin
  // <!This part only to run for Client type!>
  // following constants and variables only for performing some stuffs
  // on top of client
  const
    myconstant2=blabla;
  var
    myvar2=blabla;
  // procedure 3
  // procedure 4
end

Is there a way to manage a specific part of the code to run according the type of installation running?

Thanks.


Solution

  • Use WizardSetupType support function.

    You will probably want to check it in CurStepChanged event function.

    procedure ApplicationServer;
    begin
      // procedure 1
      // procedure 2
    end;
    
    procedure Client;
    begin
      // procedure 1
      // procedure 2
    end;
    
    procedure CurStepChanged(CurStep: TSetupStep);
    var
      SetupType: string;
    begin
      Log(Format('CurStepChanged %d', [CurStep]));
    
      if CurStep = ssInstall then
      begin
        SetupType := WizardSetupType(False);
    
        if SetupType = 'application' then
        begin
          Log('Installing application server');
          ApplicationServer;
        end
          else
        if SetupType = 'client' then
        begin
          Log('Installing client');
          Client;
        end
          else
        begin
          Log('Unexpected setup type: ' + SetupType);
        end;
      end;
    end;
    

    The Pascal script does not support local constants, only global constants.

    It's not clear anyway, what you want, if you want a local constant or initialize a global constant conditionally. You cannot do the latter anyway, a constant is constant, it cannot have a different value.

    The same with your variables. Are these local variables or do you want to set a value to a global variable conditionally?