Mutley2003
asked on
COM Objects and events
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.
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.
ASKER
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?
* 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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...