As the service is not an ordinary application it`s
debugging is complicated enough. Usually to debug the Delphi service
application you should start it from the IDE without any switches (I
mean installation switches only, of course your application can use
it`s own switches if necessary). After it starts you will have 15 seconds
(30 seconds are mentioned in other sources) to start the service from
the control panel or from the command prompt. Only after these operations
the service is considered to be started and you can debug it. To stop
it you will have to use the control panel or command prompt again. As
for me it is not convenient but you can use this approach to debug the
SvCom application too.
But there is another way. Go to the Run|Parameters dialog
and enter the /debug switch in the Parameters field.
Now start our example from the IDE as you do it with the
ordinary applications. The application starts and you see the window
that looks like this one:
Important note: You will need the DebugNTService.dll library
to be available via PATH. This library is installed by SvCom setup to
the System32 directory by default.
When started with /debug switch the SvCom application
does not start as a service. It just emulates the behaviour of the Windows
NT Service Control Manager. If you are a registered user you can look
into the SvCom_NTService unit to check how it works. After starting
in debug mode it calls the debugNTServiceX.dll and cause it to show
the service control window. This window shows the status of service
and can be used to control it. The caption of this window shows the
path of the SvCom application and each page in the multi-page control
represents one service of application. In our case there is only one
service in it so you will see only one page. The State and Type tabs
show the state of service and its configuration respectively. The set
of buttons is used to control the service. In addition you will see
a small round icon on the tray. The color of icon corresponds to the
current service state. The debug window becomes invisible when minimized.
Dblclick this tray icon to restore the debug window.
Well, after this brief description you can try to trace
our example. Set breakpoints on the OnStart, OnStop event handlers and
on the Beep call itself. Press the Start/Continue button and you will
see that Delphi debugger stops at the breakpoint in OnStart event handler.
Continue execution and the debugger will stop on the Beep call. So,
you can trace the SvCom application as an ordinary exe. You can start
and stop it as many times as you need and you don`t have 15 seconds
time limitations and you don`t have to switch on between Delphi and
control panel or command prompt. Finally, you can use this debug mode
to start you service application as an ordinary executable! In addition
I can say that the nearest SvCom version will support the /autostart
switch. Started with /debug and /autostart switches SvCom application
starts as ordinary executable and automatically starts all its services.
The debug window minimizes itself automatically so you see only icon
of the tray. Unfortunately current version of SvCom (1.1) does not support
this functionality. Please be patient.
Well, this step finishes the SvCom Example N 1. Continue
with next examples to learn more about SvCom.