Development steps:
1, new->other->service application
2, now a service program framework has been set up
Open the Service1 window with a few properties to illustrate:
Allowpause: Whether to allow pause
Allowstop: Whether to allow stop
Dependencies: Sets the dependency of the service, whether the start of the service depends on a service or group
DisplayName: The name displayed in the Services window
Interactive: When set to true, you can interact with the Windows desktop and this setting is set to true if we want to display the form in the service.
The other servicetype must be StWin32
Password: Password
StartType: Startup mode
3. If we want the service to interact with the form, the steps are as follows:
Create a new form in the project Fmmain and then write the code in the Service1 onstart
Procedure Tservice1.servicestart (Sender:tservice; var started:boolean);
Begin
Started: = True;
Svcmgr.Application.CreateForm (Tfmmain, Fmmain);
Fmmain.show;
End
OnStop's Code
Procedure Tservice1.servicestop (Sender:tservice; var stopped:boolean);
Begin
Stopped: = True;
Fmmain.free;
End
This will show the newly created form when the service is started.
4, after the completion of the compilation, we can install the service, the installation method is:
Execute the Appname/install in the cmd window, such as F:bookdserviceproject1.exe/install, so the installation is complete.
5, similarly, the deletion is also in the cmd window input command appname/uninstall such as F:bookdserviceproject1.exe/uninstall
about other:
1, about the service program debugging if we develop a service with multiple forms, the program debugging is undoubtedly a big problem in fact, the service program can be changed to a standard WIN32 project, in order to prevent constant change to change, we can add a compile condition, Compile conditions to switch the build service program or ordinary executable program, assuming that the compilation condition is Normalapp, in the following places need to join the compilation conditions in the project file, the cell reference
{$IFDEF Normalapp}
Forms,
{$ELSE} Svcmgr,
{$ENDIF}
Engineering initialization
{$IFDEF Normalapp}
Application.initialize;
Application.createform (Tfmmain, Fmmain);
Application.Run;
{$ELSE}
If not application.delayinitialize or application.installing then
Application.initialize;
Application.createform (TService1, Service1);
Application.Run;
{$ENDIF}
This allows us to switch between the service program and the normal window program by adding/removing Normalapp compiler conditions.
Delphi Development Windows Service Program