Maiken Roskilde Maiken Roskilde - 4 months ago 34
Pascal Question

Inno Setup syntax error 2

Once again I am fighting with Pascal syntax.

I just don't get it where begin and end should be used.

My current approach is this, but Inno Setup tells me that a semicolon is expected in the line "if IsServiceRunning('oscmaintenanceservice') = true then"

Can anybody shed some light on this?

Thank you!

begin
if (CurStep=ssInstall) then
MsgBox('ssInstall.', mbInformation, MB_OK);
if IsServiceInstalled('oscmaintenanceservice') = true then
MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);
if IsServiceRunning('oscmaintenanceservice') = true then
MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);
if not StopService('oscmaintenanceservice') = true then
MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
else
MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
if not RemoveService('oscmaintenanceservice') = true then
MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
else
MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
else
MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
end;
else
MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
if (CurStep = ssPostInstall) then
DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
PinAppTo(ExpandConstant('{app}\OSC.exe'), pdStartMenu);
if (IsHigherThanWindowsXP()) then
begin
PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);
end;
if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'),'oscmaintenanceservice','oscmaintenanceservice','desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) = true then
begin
MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);
end;
if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
begin
MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK);
end

Answer

This is a version of your code with the minimal number begin, end and ;.

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    MsgBox('ssInstall.', mbInformation, MB_OK);

    if IsServiceInstalled('oscmaintenanceservice') then
    begin
      MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);

      if IsServiceRunning('oscmaintenanceservice') then
      begin
        MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);

        if not StopService('oscmaintenanceservice') then
          MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK)
        else
          MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);

        if not RemoveService('oscmaintenanceservice') then
          MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK)
        else
          MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
      end
        else MsgBox('ssInstall: Service not running.', mbInformation, MB_OK)
    end
      else MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK)
  end;

  if CurStep = ssPostInstall then
  begin
    DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
    PinAppTo(ExpandConstant('{app}\OSC.exe'),  pdStartMenu);

    if IsHigherThanWindowsXP() then
      PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);

    if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'), 'oscmaintenanceservice', 'oscmaintenanceservice', 'desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) then
    begin
      MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);

      if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
        MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK)
    end;
  end;
end;

For a comparison, below is an equivalent version of the code with all the optional/redundant begin, end and ;. Maybe it will help you to understand.

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    MsgBox('ssInstall.', mbInformation, MB_OK);

    if IsServiceInstalled('oscmaintenanceservice') then
    begin
      MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);

      if IsServiceRunning('oscmaintenanceservice') then
      begin
        MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);

        if not StopService('oscmaintenanceservice') then
        begin
          MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
        end
          else
        begin
          MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
        end;

        if not RemoveService('oscmaintenanceservice') then
        begin
          MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
        end
          else
        begin
          MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
        end;
      end
        else
      begin
        MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
      end;
    end
      else
    begin
      MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
    end;
  end;

  if CurStep = ssPostInstall then
  begin
    DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
    PinAppTo(ExpandConstant('{app}\OSC.exe'),  pdStartMenu);

    if IsHigherThanWindowsXP() then
    begin
      PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);
    end;

    if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'), 'oscmaintenanceservice', 'oscmaintenanceservice', 'desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) then
    begin
      MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);

      if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
      begin
        MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK);
      end;
    end;
  end;
end;

Once you get your head around this, please accept the duplicate, or delete your question altogether.