?
Solved

COM server instancing

Posted on 1998-07-28
6
Medium Priority
?
213 Views
Last Modified: 2010-05-18
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?
0
Comment
Question by:lowlevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Expert Comment

by:_art_
ID: 1358815
Have you tried ciMultiInstance???? That is it I believe, at least thats what help says.
0
 
LVL 1

Author Comment

by:lowlevel
ID: 1358816
Nope, it ain't.
0
 
LVL 1

Accepted Solution

by:
AndersWP earned 1000 total points
ID: 1358817
I think I have a solution to your problem: To get a handle to an already running instance of an automation server, use the GetActiveObject function.

The following code snippet should give you an example:

Var
  Server: Variant;

Server:=Nil;

Try
  Server:=GetActiveOLEObject(<Your server name>);
Except
End;

Try
  If VarType(Server)<>varDispatch Then
    Server:=CreateOLEObject(<Your Server Name>);
Except
  ShowMessage('Could not create server');
End;

In this example, <Your Server Name> should be replaced with the name of your automation server. After executing this code, the variant variable Server will contain a reference to the server.
The code will first try to establish a reference to an existing instance of the server. If this fails (because no instance is running), a new instance is created.

I hope this will help you.

Greetings,
AndersWP

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:lowlevel
ID: 1358818
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.
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1358819
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
0
 
LVL 1

Author Comment

by:lowlevel
ID: 1358820
yup, thanx :)

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question