views:

130

answers:

3

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 trying 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??

+1  A: 

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

François
And can I put a socket server on it?
O Engenheiro
Of course you can. You can put any non-visual component on it. See @ldsandon's answer.
Ken White
We create the sockets through code...
François
+7  A: 

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.

ldsandon
+1  A: 

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;
Scott W