Out Process COM Server using Delphi 4 ????

I am currently working on an out process com server using delphi. This
out process com server has a set of interfaces, with no co classes.
There is one main interface 'Imain' through which the other interfaces
can be obtained. The com client that uses this com server will be using
just one Imain interface to talk to the com server. This Imain interface has to be obtained from the com server which will be internally
instantiating the object and then providing the interface to the com client.

The problem is that I just can't find a way to do this. I.e.
instantiating the object within the com server and then passing on the
interface to the com client.

One good example of this situation would be that suppose I am developing

microsoft word and when I am working with another application, I can
talk to microsoft word com server and set certain global properties like

activedocument, without having to instantiate microsoft word object
myself. The com server does it for me. I want the same kind of
functionality to be provided by my com server.

Any example code for the com server would be appreciated.

Please note that all my interface implementation classes are derived
from TAutoIntfObject.

Your prompt response is eagerly awaited

Thank you,
Who is Participating?
EdHillmannConnect With a Mentor Commented:
Hi Goradia.  If I understand correctly, Delphi should be able to handle the main COM Implementation (read Server) object instantiation as long as it's defined as a TAutoObject.  When you use a TAutoObject, it will associate it with a ClassFactory, and the Factory is what the Windows system uses to create the server object.  And it's this Server object that gets passed back to the client.

For example, if I was starting from scratch, I'd start a new application.  Then create a New Automation Object (providing its Name and Instantiation).  This will be your main interface (we'll call it IMainInterface for clarity).  This will provide you with a type library and an implementation unit.  If you notice the bottom of the implementation unit, you'll see a line that creates the AutoObjectFactory.

So, now in your type library, you can define your remaining interfaces in the type library without creating corresponding CoClasses.

Once you have all the interfaces defined (with still only one CoClass, which will be called MainInterface going by our example), you can define the functions/properties on IMainInterface that allows a client to access another interface.  The IDL, would look like this...

   interface IMainInterface: IDispatch
    [propget, id(0x00000001)]
    HRESULT _stdcall Property1([out, retval] ISubIntf1 * Value );

The above example is IMainInterface which has a property which returns an implementation of the ISubIntf1 (where ISubIntf1 is defined in IMainInterface's type library).

That's the deal on the interface.  As far as the implementation object for IMainInterface, it would need to construct the TAutoIntfObject's during it's Initialize procedure.  Not it's Create procedure.  And it's interface functions would then provide the appropriate TAutoIntfObjects for the IMainInterface function call.

Note: you could also delay the AutoIntf object construction until the first time the appropriate function is called...

The only thing you'd want to remember is to handle the AutoIntf objects when the TAutoObject is destroyed.

Hope this helps.  Let me know if you want more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.