Inno Setup语法错误2
Inno Setup syntax error 2
我又一次与 Pascal 语法作斗争。
我只是不明白应该在哪里使用开始和结束。
我目前的做法是这样的,但是 Inno Setup 告诉我在行 "if IsServiceRunning('oscmaintenanceservice') = true then"
中需要一个分号
任何人都可以阐明这一点吗?
谢谢!
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
这是您的代码版本,其中包含最小数量 begin
、end
和 ;
。
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;
为了进行比较,下面是包含所有 optional/redundant、begin
、end
和 ;
的等效代码版本。或许能帮助你理解。
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;
一旦您明白了这一点,请接受重复的问题,或者完全删除您的问题。
我又一次与 Pascal 语法作斗争。
我只是不明白应该在哪里使用开始和结束。
我目前的做法是这样的,但是 Inno Setup 告诉我在行 "if IsServiceRunning('oscmaintenanceservice') = true then"
中需要一个分号任何人都可以阐明这一点吗?
谢谢!
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
这是您的代码版本,其中包含最小数量 begin
、end
和 ;
。
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;
为了进行比较,下面是包含所有 optional/redundant、begin
、end
和 ;
的等效代码版本。或许能帮助你理解。
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;
一旦您明白了这一点,请接受重复的问题,或者完全删除您的问题。