开发者

Use a Datamodule in a Service Application

I wrote my Win32 App to test and debug. I've created a datamodule with all functionality needed to run the TCP sockets and IBDatabase components.

After successfully testing the Datamodule in the Win32 application environment I am try开发者_Python百科ing to hook the Datamodule into a Service Application template that I created, I can get nowhere in getting it to run.

Could someone indicate whether this strategy of using a Datamodule with Component functionality encapsulating the primary service functions is workable and give a simple template example of how to hook it up if it is??


You have to create and initialize your datamodule in the service start event. Be careful that the datamodule should not open dialog boxes or the like, or it will hang waiting for input that could never come (there are ways to have a service communicate with the user desktop, but a good service should avoid them). But without looking at your code, it is difficult to say what is going wrong.


As others have mentioned, yes, this is definitely possible. For my implementation, I actually just make my data module as auto-create in Project Options. Then my service code is very light weight and boils down to this:

procedure TMyService.ServiceStart(Sender: TService; var Started: Boolean);
begin
  Started := myDataModule.Startup;
end;

procedure TMyService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
  myDataModule.Cleanup;
  Stopped := True;
end;


Yes, you can have a DataModule working in a Service Application.
That's exactly what we have for our middle tier appservers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜