I’m looking into creating a TService Descendant so that when writing a new service I’m not reinventing the wheel so to speak.
I have created an ancestor worker thread that this TService descendant would be responsible for managing (decendant threads implement the code for the service).
This TService descendant will also have a class for writing to a custom Windows event log, and a thread that checks for new versions of the service from a http server, then updates itself when required.
My problem is what is the best way to instantiate the TService descendant from the project source?
Should the descendant be a pure class or have a dfm/datamodule?
You can “just” start a new service application. That will create a TService descendant for you (in its own datamodule by the way)? It also takes care of instantiating the service for you in the dpr. (Starting a new service app: File | New | Other | Delphi Projects | Service Application). Plus it will make sure that the proper units are included as a service application needs the “Application” global var to refer to a TServiceApplication instance and not an instance of what is instantiated for a normal VCL Forms application.
See Service OnExecute fails, spawned thread is not executed for a bare bones service app implementation.
DataModules support Visual Form Inheritance just like Forms do. So, if you want to create descendants, you can add a new service datamodule to your dpr and inherit from the service already created by the IDE. Then use either the project options | forms to control which one is instantiated from the dpr (the first one in the right hand list) or edit the dpr manually.
In other words: use the TService1 created when you create a new service app as your common base and create your descendent services by inheriting from that base using visual form inheritance. File | New | Other | Inheritable Items, should list your first Service data module.