Board index » delphi » COM objects creating other COM objects

COM objects creating other COM objects

I have a question regarding the creation of COM objects inside other
COM objects.

For example COM1 has as a private member variable, called m_com2,
which if of of another class: COM2.. COM2 I would want to expose to
the client as a property of COM1 or part of a IEnumVariant collection.

When the client creates COM1 and COM1 in it's construction creates
COM2 should the member variable m_com2 be of type ICOM2 or TCom2?

With an ICOM2 type I can only access the public methods and properties
like any COM object. But creating a TCom2 I cannot access the accesor
methods that the type library editor creates for properties and
methods. Why are they protected and not public? I would want to create
a TCOM2 and use it's accesor methods.

Any comments, ideas?

Regards,
Diego Barros

 

Re:COM objects creating other COM objects


If use have a TCom2 reference be sure that you use "ObjAddRef" to increment
it's reference count, else get AV's. I just had this problem. In fact in
some cases I keep both references eg a ICom and a TCom.

It will also depend if your server is in process or out of process.

Perhaps the only safe way - is to use CoCreateInstance to create your second
object.

You can If you want to change the methods to be public, but beware that the
properties declared in your type lib are only accessable using your ICom
interface, if you use the TCom, then you have to use Get_ and Set_ methods
instead.

Normally direct access to the properties using TCOm is faster as the
safecalls do have a higher overhead, and if you object is to referenced by
VB script, then you are limited in your data types.
Myles.

Quote
Diego Barros wrote in message <3728535c.15077...@forums.borland.com>...
>I have a question regarding the creation of COM objects inside other
>COM objects.

>For example COM1 has as a private member variable, called m_com2,
>which if of of another class: COM2.. COM2 I would want to expose to
>the client as a property of COM1 or part of a IEnumVariant collection.

>When the client creates COM1 and COM1 in it's construction creates
>COM2 should the member variable m_com2 be of type ICOM2 or TCom2?

>With an ICOM2 type I can only access the public methods and properties
>like any COM object. But creating a TCom2 I cannot access the accesor
>methods that the type library editor creates for properties and
>methods. Why are they protected and not public? I would want to create
>a TCOM2 and use it's accesor methods.

>Any comments, ideas?

>Regards,
>Diego Barros

Other Threads