Board index » delphi » Two COM-Servers in one EXE

Two COM-Servers in one EXE


2003-07-22 05:39:36 AM
delphi141
Hello,
I have two COM-Servers in one EXE. In both units in the
initalization-section a
TComObjectFactory.Create(ComServer, ...);
is done.
As I understood COmServer is a global variable from the unit ComServ
which holds things like how many times the com-object is referenced a.
s. o.
If both units do a TComObjectFactory.Create(ComServer, ...); the last
one wins and overwrite the ComServer from the previous object.
Introducing a new global variable ComServer1 doens't solve the problem
- the com-object don't start anymore.
Serveral questions:
Is it a problem if I register in one exe/dll more then one Com-Server
and overwrite the ComServer-var with every newly registered Com-Server?
How can I hold a reference on each registered Com-Server (my approach
with the global var don't work)?
Is it possible to release all references to a ComServer (i. e. if I do
a ComServer.ObjectCount I get 10 and want to set it to 0 though that
the delphi ComServ-TerminateProc don't pop up the warning that a
ComServer is ended with references on it)?
Thanks
Stefan
 
 

Re:Two COM-Servers in one EXE

hi Stefan,
You've got 2 units then i imagine you generated 2 xxx_TLB.pas.
In this case, the "ComServer" global variable is not designed to handle the
second TLB.
IMHO, this problem is linked to Delphi TLB automanagement and ComServer
object.
Look at this thread it describes how to use 2 TLB :
groups.google.com/groups
TF-8&output=gplain
Something like this should do the trick to create the right object with the
right typelib :
var
TypeLib: ITypeLib;
begin
LoadTypeLib(PWideChar(WideString(Paramstr(0)+'\'+IdTypeLib)),TypeLib);
if assigned(TypeLib) then
inherited Create(TypeLib,IntfId); // TAutoIntfObject create
...
end;
pascal
"Stefan Westner" <XXXX@XXXXX.COM>a écrit dans le message de news:
XXXX@XXXXX.COM...
Quote
Hello,

I have two COM-Servers in one EXE. In both units in the
initalization-section a

TComObjectFactory.Create(ComServer, ...);

is done.

As I understood COmServer is a global variable from the unit ComServ
which holds things like how many times the com-object is referenced a.
s. o.

If both units do a TComObjectFactory.Create(ComServer, ...); the last
one wins and overwrite the ComServer from the previous object.

Introducing a new global variable ComServer1 doens't solve the problem
- the com-object don't start anymore.

Serveral questions:
Is it a problem if I register in one exe/dll more then one Com-Server
and overwrite the ComServer-var with every newly registered Com-Server?
How can I hold a reference on each registered Com-Server (my approach
with the global var don't work)?
Is it possible to release all references to a ComServer (i. e. if I do
a ComServer.ObjectCount I get 10 and want to set it to 0 though that
the delphi ComServ-TerminateProc don't pop up the warning that a
ComServer is ended with references on it)?

Thanks

Stefan