我已写完的一个程序,我想把它以服务方式启动,请问该修改代码?(100分)

  • 主题发起人 主题发起人 driayu
  • 开始时间 开始时间
D

driayu

Unregistered / Unconfirmed
GUEST, unregistred user!
我在网上找到有资料说:<br>&nbsp;不要在工程源文件中包括Forms和HttpApp单元.SvcMgr、Forms和HttpApp都定义了一个全局的Application对象,这会导致服务程序中出现冲突. &nbsp; <br><br>可我的源文中包抱有窗体,是不是不能做成服务方式启动了?请各位高手帮忙.
 
可以的,你可以这样做,查询服务的状态,如果存在,就启动他,不存在的话就注册、启动<br>在工程中这样写:<br>var<br>&nbsp; &nbsp; i:Integer;<br><br>{$R *.res}<br><br>begin<br>&nbsp; &nbsp; i:=QueryServiceState('MyService');<br>&nbsp; &nbsp; case &nbsp;i of<br>&nbsp; &nbsp; 0:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if &nbsp;wInstallService('MyService','ServiceName','服务描述',ParamStr(0)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; wServiceStart('','MyService');<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; 1:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; wServiceStart('','MyService');<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;//case<br>&nbsp; &nbsp; Forms.Application.Initialize;<br>&nbsp; &nbsp; forms.Application.CreateForm(TMainForm, MainForm);<br>&nbsp; &nbsp; forms.Application.CreateForm(TForm1, Form1);<br>&nbsp; &nbsp; svcmgr.Application.Initialize;<br>&nbsp; &nbsp; svcmgr.Application.CreateForm(TMyService, MyService);<br><br>&nbsp; &nbsp; svcmgr.Application.Run;<br>&nbsp; &nbsp; forms.Application.Run;<br>end.<br><br>还有,别忘了加入 一个TService
 
后退
顶部