Board index » delphi » Passing a TComponent from COM-server to COM-client

Passing a TComponent from COM-server to COM-client

You can't pass a TComponent instance with COM. Because COM-Objects can be in
a different process or even on a different machine. One of the great
features of COM is that it is language independent, this means you can only
pass parametertypes wich can be handled by all languages.

I would suggest to drop the Delphi database components and take a look at
ADO. ADO works with interface pointers wich can be safely used as
parameters.

Rob Lans
Software Engineer
NOB Interactive

Quote
Timo van Noppen wrote in message <79mgj2$...@forums.borland.com>...
>As a newbie in COM-world I am trying to make the following getting to work.

>I have created a COM-server that will open a TDatabase-connection when
>created. Now I would like the client to use this connection when it needs
>access to the database. Thus, not a new connection with the same parameters
>but the existing one.

>Normally you can pass pointers to objects using LongInt between different
>Forms etc., but this does not work. Obvious probably?

>But is there a way to accomplish this?

>Regards,
>Timo

 

Re:Passing a TComponent from COM-server to COM-client


Thank you for your reply.

Very dissapointing however.

The database is not the only component I would like to pass.
To go off-topic now: is there any other mechanism I could use to pass
pointers to TComponents from one application to another (I only have D4 Pro,
so please no C/S solutions) and are there any refs to ie url's to this
subject.

Regards,
Timo

Rob Lans heeft geschreven in bericht <79mhjp$...@forums.borland.com>...

Quote
>You can't pass a TComponent instance with COM. Because COM-Objects can be
in
>a different process or even on a different machine. One of the great
>features of COM is that it is language independent, this means you can only
>pass parametertypes wich can be handled by all languages.

>I would suggest to drop the Delphi database components and take a look at
>ADO. ADO works with interface pointers wich can be safely used as
>parameters.

>Rob Lans
>Software Engineer
>NOB Interactive

>Timo van Noppen wrote in message <79mgj2$...@forums.borland.com>...
>>As a newbie in COM-world I am trying to make the following getting to
work.

>>I have created a COM-server that will open a TDatabase-connection when
>>created. Now I would like the client to use this connection when it needs
>>access to the database. Thus, not a new connection with the same
parameters
>>but the existing one.

>>Normally you can pass pointers to objects using LongInt between different
>>Forms etc., but this does not work. Obvious probably?

>>But is there a way to accomplish this?

>>Regards,
>>Timo

Re:Passing a TComponent from COM-server to COM-client


What you could try is having the another Component that is declared
something like this

TMyComp = class( TComponent)
  somefield: integer;
  somefield: integer;
end;

TInterfaceComp = class( TComponent, IInterface)
  private
    MyComponent : TMyComp;
  public
    procedure InterfaceMethod1;
    procedure InterfaceMethod2;
    procedure InterfaceMethod3;
end;

doing it this way, you can expose what the component does to the outside
world yet still keep your original component.

Quote
Timo van Noppen wrote in message <79mk4g$v...@forums.borland.com>...
>Thank you for your reply.

>Very dissapointing however.

>The database is not the only component I would like to pass.
>To go off-topic now: is there any other mechanism I could use to pass
>pointers to TComponents from one application to another (I only have D4
Pro,
>so please no C/S solutions) and are there any refs to ie url's to this
>subject.

>Regards,
>Timo

>Rob Lans heeft geschreven in bericht <79mhjp$...@forums.borland.com>...
>>You can't pass a TComponent instance with COM. Because COM-Objects can be
>in
>>a different process or even on a different machine. One of the great
>>features of COM is that it is language independent, this means you can
only
>>pass parametertypes wich can be handled by all languages.

>>I would suggest to drop the Delphi database components and take a look at
>>ADO. ADO works with interface pointers wich can be safely used as
>>parameters.

>>Rob Lans
>>Software Engineer
>>NOB Interactive

>>Timo van Noppen wrote in message <79mgj2$...@forums.borland.com>...
>>>As a newbie in COM-world I am trying to make the following getting to
>work.

>>>I have created a COM-server that will open a TDatabase-connection when
>>>created. Now I would like the client to use this connection when it needs
>>>access to the database. Thus, not a new connection with the same
>parameters
>>>but the existing one.

>>>Normally you can pass pointers to objects using LongInt between different
>>>Forms etc., but this does not work. Obvious probably?

>>>But is there a way to accomplish this?

>>>Regards,
>>>Timo

Re:Passing a TComponent from COM-server to COM-client


Timo,
  You may pass class instances around via COM, but they must be marshalled a
bit differently...  For instance, you may stuff
  an instance of a class into a VarArray of byte and then send that to another
COM object. (I believe that Delphi informant
  had an article that went over this, but unfortunately I can't find the
article number)
  You may want to look into Midas (ClientDataSets, etc..) to see if that is
what you are looking into doing for database connectivity.

Good Luck,
--
-Adam
Delphi Developer Support

Due to my workload, personal email more than likely won't get a
reply.

Support options are detailed at http://www.inprise.com/devsupport/
I am unable to answer support questions via email at this time.

Quote
Timo van Noppen wrote:
> As a newbie in COM-world I am trying to make the following getting to work.

> I have created a COM-server that will open a TDatabase-connection when
> created. Now I would like the client to use this connection when it needs
> access to the database. Thus, not a new connection with the same parameters
> but the existing one.

> Normally you can pass pointers to objects using LongInt between different
> Forms etc., but this does not work. Obvious probably?

> But is there a way to accomplish this?

> Regards,
> Timo

Re:Passing a TComponent from COM-server to COM-client


As a newbie in COM-world I am trying to make the following getting to work.

I have created a COM-server that will open a TDatabase-connection when
created. Now I would like the client to use this connection when it needs
access to the database. Thus, not a new connection with the same parameters
but the existing one.

Normally you can pass pointers to objects using LongInt between different
Forms etc., but this does not work. Obvious probably?

But is there a way to accomplish this?

Regards,
Timo

Re:Passing a TComponent from COM-server to COM-client


The only way I was able to share a database handle available in a server is
by making the COM Server an in-process server (ActiveX DLL) so that the
client and the server can share the same database connection.

You do can pass a TComponent from one application to another using COM
channel using the VarArray /OleVariant data types.... But you won't be able
to share the same component in both the exes...  The target exe creates a
new instance of TComponent and populates it with state information
information  passed using the VarArray .... Also, you have to make sure that
you registered the TComponent class type before you do this.

If you need more info, please let me know.

-Srini

--

(Srinivas Junnuru)
Note: Pl. remove NOSPAM from my address to e-mail me.

Quote
Timo van Noppen wrote in message <79mgj2$...@forums.borland.com>...
>As a newbie in COM-world I am trying to make the following getting to work.

>I have created a COM-server that will open a TDatabase-connection when
>created. Now I would like the client to use this connection when it needs
>access to the database. Thus, not a new connection with the same parameters
>but the existing one.

>Normally you can pass pointers to objects using LongInt between different
>Forms etc., but this does not work. Obvious probably?

>But is there a way to accomplish this?

>Regards,
>Timo

Re:Passing a TComponent from COM-server to COM-client


If use only inproc servers you can cast the TComponent instance to a longint
and pass it to the other side. The problem is that COM was designed  to be
language independent, so you can only use parameters wich are  understoud by
all COM compatible languages.

Rob Lans
Sofrware Engineer
NOB Interactive

Quote
Timo van Noppen wrote in message <79mk4g$v...@forums.borland.com>...
>Thank you for your reply.

>Very dissapointing however.

>The database is not the only component I would like to pass.
>To go off-topic now: is there any other mechanism I could use to pass
>pointers to TComponents from one application to another (I only have D4
Pro,
>so please no C/S solutions) and are there any refs to ie url's to this
>subject.

>Regards,
>Timo

Other Threads