Link to home
Start Free TrialLog in
Avatar of lowlevel
lowlevel

asked on

COM server instancing

Consider an application X that uses interfaces iA and iB.
iA and iB are implemented by txA and txB, which are tAutoObject descendants.
Suppose iB stores some configuration information, and iA implements some functionality that needs the config info from iB.

A problem arises when iA's client (X) wants to touch the config-info aswell, since both X and iA need *the same* reference to iB. (I think!)

In the unit that implements txA, i have the following line:
  tAutoObjectFactory.Create(ComServer, txA, Class_A, ciSingleInstance);

However, after digging into the VCL sourcecode, it seems that the ciSingleInstance parameter is never used again. It is only stored in the classfactory as a private variable.

Given the above scenario, i do NOT get the same references to iB in iA and X.

I've thought of creating a dll-global variable that gets set in txB.initialize if it is nil.. But how do I tell the second instance of iB to abort it's own initialization and use the dll-global variable instead?

And even then, it does not solve my original problem (X and iA using iB) when X and iA are in different address spaces. That is not a practical situation yet, but I can see it becoming one :(

Got any help?
Avatar of _art_
_art_

Have you tried ciMultiInstance???? That is it I believe, at least thats what help says.
Avatar of lowlevel

ASKER

Nope, it ain't.
ASKER CERTIFIED SOLUTION
Avatar of AndersWP
AndersWP

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works like a dream :)

Would you also happen to know why i cannot do something like
var dispatch : variant;
    een      : iEen;
begin
  try
    dispatch:=getActiveOLEObject (serverName);
  except
  end;

  if varType(dispatch)<>varDispatch
    then een:=coEen.create
    else een:=iEen(getActiveOLEObject (serverName));
end;

this will compile, it'll even run, but the iEen pointer is invalid and thus causes access violations.
I'd like to be able to convert it to a specific interface type because I like the type-checking that delphi does pre-compiling.
You cannot typecast a Variant referencing an automation server directly to an interface type.

To work with interfaces rather than variants, you can do something like the following:

  Try
    een:=GetActiveOleObject(<Your Server Name>) As IEen;
  Except
    On e:EOleError Do
      een:=CoEen.Create;
  End;

The trick here is that the As operator will do the appropriate conversion to your interface type.

I hope this is what you ment.

Regards,
AndersWP
yup, thanx :)