Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

COM Objects and events

Posted on 2004-10-04
4
Medium Priority
?
158 Views
Last Modified: 2010-04-05
I am trying to get my head around the way COM objects fire events, and how I can process them (the events and any data they send).

Can someone rough out some code for

a) a COM object that is callable from javascript (maybe from an html page) and "broadcasts" a string (say the current date and time) via an event

b) an event sink receiver that gets and displays that string.

I REALLY don't understand what is going on here .. is it some form of interprocess communication? what about shared memory issues?

Code might help me understand.
0
Comment
Question by:Mutley2003
[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
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12215853
Nope. Basically, it is very simple. You provide the COM object an interface to another COM object. And the COM object just calls the methods of the other interface. Something like:

type
  IFooEvent = interface
    procedure DoFire;
  end;
  IFoo = Interface
    procedure Fire;
    function GetFooEvent: IFooEvent;
    procedure SetFooEvent(Value: IFooEvent);
    property FooEvent: IFooEvent read GetFooEvent write SetFooEvent;
  end;

The COM DLL/EXE would create a type around IFoo. The Foo method just checks if a value is assigned to the FooEvent property and if it has a value, it just calls IFooEvent.DoFire.
Your application that calls the COM object must therefore contain a class that implements IFooEvents so it can send this class to the COM object. Basically, what you just get are two COM objects that communicate with one another through function calls.

With DCOM/COM+, there are also stubs and proxies involved, resulting in the communication between the two COM objects to be marshalled, send over the network and then unmarshalled again. This is just the Windows support for DCOM/COM+ and you don't have to worry about it.

If you use the Delphi COM wrapper wizard, this wizard will create the additional class for the events in your code for you.

However, it gets more complicated if multiple clients want to receive events from the COM server. In that case, the server needs to maintain a list of client COM objects, and call them all on events. This is done through the event sink. And it gets more complicated than this. But basically,COM events just mean the client has a COM object too...
0
 

Author Comment

by:Mutley2003
ID: 12257075
ok, I have one COM object talking to another (as in, calling the methods of another). Let me see if I have this correct
* the COM server fires the events
* the COM client(s) receives them.

But I am missing a bit of the puzzle right here. Is the standard windows messaging being employed .. some PostMessage or SendMessage or somesuch? How does the client know that the event has happened?


0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 2000 total points
ID: 12262101
Nope. If it's an in-process COM object, the message system is just a matter of calling the procedures. The COM object is located in the same process space as the client application.
An out-of-process COM object does require some inter-proces communication but this is handled by Windows itself. If client and server are located on the same system, Windows will just use the pipe mechanism that it has. If client and server are on different systems, Windows will use TCP/IP for the communication and it has some ports reserved for this purpose. (Which you have to keep open if you have a firewall, else it won't work.)

This messaging system is completely handled by Windows. This is arranged by the type library which just tells Windows how it should marshall and unmarshall all the data that needs to be sent between the two sides.

You might want to read http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomg/html/msdn_comppr.asp and other MSDN articles about COM.
0

Featured Post

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.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

688 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