Work with a COM object using CLSID

In my COm object implementation, there is this chunk of code:

  TAutoObjectFactory.Create(ComServer, TBrowser, Class_Browser, ciInternal, tmApartment);

1. Does an instance of TBrowser is created automatically at the stratup of my application?
2. What if I want to use this instance of the object inside my application and not creating another instance?
3. Can it have something to do with GetActiveOleObject?
Who is Participating?
Russell LibbyConnect With a Mentor Software Engineer, Advisory Commented:

Being an OLE server makes a difference, because you may be controlled by another app. The the instancing comes into play (is there already an interface, etc..). Looking at the first comment though:

TAutoObjectFactory.Create(ComServer, TBrowser, Class_Browser, ciInternal, tmApartment);

assures that you will not be. The ciInternal tells delphi NOT to register this class factory with COM, thus no app can get an instance of this interface (other than your own app).

In your app code
1.) in your host, include both the source unit and tlb unit
2.) var (or make property of form, or whatever)
    pbrowser:   IBrowser;
3.) in FormCreate() (or applicable place)
4.) In GetExternal()
    return pbrowser
5.) Your host can also use the pbrowser variable to access the interface (which i assume in turn accesses your application/form/etc...)


Russell LibbySoftware Engineer, Advisory Commented:

1.) The code you are describing above does not create an instance of your com class. It creates an instance of a class factory FOR your com class (gets added to the factory list in the ComClassManager.)

2.) See 1

3.) No, GetActiveOleObject (wrapper to GetActiveObject) requires that the COM class be previously registered using RegisterActiveObject.

What is it exactly that you are trying to achieve? Do you only wish one instance of you com class to be loaded by other clients? Or is your application creating an instance of the class, and you wish to get a reference to it?


pjroyAuthor Commented:

Want I want to do is to have only one instance of my COM object. The help you better understand the problem, the application has a Microsoft Money 2002 like GUI. The methods call come from either a JavaScript call through an html pages hosted by TWebBrowser, secondly from the inside of the host (Delphi code). I don't want to write a Delphi object model with a COM wrapper if it is possible for me to build everything into COM object and then using them from JavaScript and Delphi. Remember, its a standalone application and no calls come from the outside. I use window.external in Javascript to access the COM interface exposed by my application.


Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Russell LibbySoftware Engineer, Advisory Commented:


Is the COM object that your trying to create/share located in your EXE? (Is your app an OLE server). Or is the COM object located in a seperate EXE/DLL?

If in a seperate DLL/EXE, then your host EXE would simply be able to create an instance of the COM object (on startup, or where appropriate). Then when IDocHostUIHandler.GetExternal() gets called, you would pass the reference back to the web browser. This would allow both your host (delphi code) and the web browser script code to access/manipulate the same object.

If your app is an OLE server, which according to your above comment its not (quote: Remember, its a standalone application and no calls come from the outside) then things get a little more interesting. If this is the case, then let me know.

Sorry I can't help more, but it would help if you described where the COM object is located (in your exe, or some other dll/exe)

pjroyAuthor Commented:
The COM is in the same EXE for now. After my project advance, I will possibly refactor and create dll if I need to. What is the difference between those two cases?
pjroyAuthor Commented:
Sorry, I've written my question before reading your entire answer. I'll increase your point when I'll be back in 2 days and had time to test the concept. Back soon.

This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
Lukasz LachCommented:
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to rllibby http:#7146324

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.