To the main page...The list of my products...Some texts...Sample applications, tips, tricks...If you need support...


 
DCOM server in service
Step 4. Creating the automation object that lives in service

Go to the File|New dialog and select the SvCom page.

File|New dialog

Select the "Automation Object in Service" and press OK. The dialog box appears that will ask you for the name of new automation object and for the name of service that will contain this object.

Object-in-service wizard

Enter SvComObject4 as a class name and SvComSampleService4 as a service name. Please note that it MUST be the same as the name of our ComService module. Press OK button and the new automation object source will be created and added to your project. The project typelibrary will be created and necessary interface and coclass will be added too.

At this point I recommend to save all changes and reopen your project. The thing is that the Delphi does not recognizes immediately that newly created unit contains the CoClass. In spite of SvCom wizard makes necessary changes in the project source (marked by color below) Delphi ignores it until project be reopened. I've spent a lot of time trying to work around this problem but with no success.

 

uses
  SvCom_NTService,
  svcExample4 in 'svcExample4.pas' {SvComSampleService4: TComService},
  clsObject4 in 'clsObject4.pas' {SvComObject4: CoClass},
  SvComExample4_TLB in 'SvComExample4_TLB.pas';

Before continue let's look on the classfactory of our object.



 .
 .
 .
 .

uses SvCom_ComServ;

initialization
  TSvcAutoObjectFactory.Create(SvcComServer, TSvComObject4, 
  Class_SvComObject4, ciMultiInstance, 'SvComSampleService4');
end.

As you see it is not ordinary TAutoObjectFactory. The TSvcAutoObjectFactory is used instead. It implements all registration actions that are necessary to correctly install object in service into registry. The first parameter of the factory constructor is SvcComServer, not a ComServer. It is described in SvCom_ComService unit and implemented in SvCom_ComServ units so both units must be included into uses section (the SvCom wizard does it automatically when generates corresponding source file). And the most important is the last parameter of factory constructor. It is a name of ComService module that will contain our autoobject. Important: If you are going to rename ComService module do not forget to change the last parameter of factories constructors. SvCom does not checks this parameter and your DCOM server will not work if this parameter is invalid.

In fact our DCOM server in service is ready and it can be tested immediately but it does nothing yet. So let's add a method to the automation object. It can be done exactly in the same way as you do it with ordinary automation objects. Open the project's typelibrary, select the object's interface and add new method to it. Rename it to the Execute function. This function will return 'Hello from SvCom example!' string so declare the return value type of function as WideString. Press the refresh button and Delphi will add a function skeleton to the automation object source. Go to it and modify source as shown below:



 .
 .
 .
 .

function TSvComObject4.Execute: WideString;
begin
    Beep;
    result:='Hello from SvCom example !';
end;

Save all changes and compile our service application. After successful compilation install it. OK, now it is ready for testing. We shall need in client to do it.

<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | >>


 
© 1998-2014 Alexey Dynnikov