|Step 4. Creating a service form|
Apr 11, 2011. Important note. Starting from Windows Vista interactive services are prohibited by Microsoft. Service application can not show forms even if it is marked as Interactive. SvCom suggests a workaround that allows to easily communicate with user from service application. Read more about this opportunity
As you know the Delphi VCL is not thread-safe. It means that all forms of Delphi application should live in one thread. Usually it is a main thread of application. At the same time we intend to create a form that will live in the service thread, not in the main thread of application. It is possible due to trick that is described below. This trick is not limited by SvCom services only. You can use it to create Delphi forms that live in separate threads in regular (not service) applications.
Before we start I would like to discuss the idea of this trick.
Let's consider the Delphi dll compiled without packages and containing some forms. Such dll can show it`s form in ANY thread of application (but all forms of dll must be in one thread). It will be safe because the whole VCL code in this dll will live in one thread. So if you have a set of forms that should live in a separate thread then place them into one dll, compile it without packages and use! It will work and it will be thread-safe.
OK, after this introduction the implementation of
service form is easy enough. Do following steps:
Export the ShowForm procedure. To do it add the exports section to the library dpr file:
Now return to the service module source and add the OnStart event handler to it. This event handler should call the ShowForm method. Do not forget to import it from SvComLib3.dll. Necessary source changes are shown below:
Save all changes and compile both service application and it`s dll. Now our interactive service is ready for tests. Let's continue...
|<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | >>|