Solved

COM server instancing

Posted on 1998-07-28
6
210 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 250 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Show Listview image from database (String field) 5 151
Magic Software info 18 144
Get weeknumber and year from date 4 31
SQL Server Express automatically execute SQL or SP 8 37
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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