Delphi Development Windows Service Program Tutorials < a >

Source: Internet
Author: User

Development steps:
1, New->other->service Application
2, now a service program framework has been set up, open Service1 window, there are several properties explained:
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, this setting is set to true if we want to display the form in the service, and the 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
Then write the code in Service1 's 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:
Executes the appname/install in the cmd window,
such as F:\book\dservice\project1.exe/install
So the service is installed and finished.
5, similarly, the deletion is also in the cmd window input command appname/uninstall
such as F:\book\dservice\project1.exe/uninstall

about other:
1, about the commissioning of the service program
If we develop a service with multiple forms, the debugging of the program 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, through the compilation condition to switch the build service program or the ordinary executable program, assuming that the compilation condition is Normalapp, in the following places need to join the compilation condition
References to units in the project file
{$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 Tutorials < a >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.