Let's add methods to the COM-object interfaces. We'll
implement a very simple server with very simple callback - the client
application will have one button to send some text message to the server.
The server will receive this message and broadcat it to all clients
using registered callback interfaces.
First of all add the HandleEventNotification method
to the IComObjectWithEventsEvents dispinterface. Add one EventMessage
parameter of WideStringType. Note again, this interface should be implemented
by client, not server, so we just declare the interface but do not implement
Now add the RaiseEvent method to the IComObjectWithEvents
interface. Add one WideString parameter to it, set its name to "Text".
The implementation of this method will look like this one:
procedure TComObjectWithEvents.RaiseEvent(const Text: WideString);
var i: Integer;
with FConnectionPoint.SinkList do
for i:=0 to Count-1 do
if not Assigned(U) then continue;
E:=U as IComObjectWithEventsEvents;
E.HandleEventNotification('Event is raised with message: '+Text);
if Assigned(FEvents) then
FEvents.HandleEventNotification('Event is raised with message: '+Text);
The RaiseEvent method is available for client application
so it can pass the text message to the server. As you can see server
processes it easy - it iterates through registered callbacks and calls
for every registered callback instance.
The server application is ready for tests. Install
it as usual - if you wish to test it in service mode immediately then
run it once with /reinstall switch. If you wish to trace it in IDE first
then run it with /reinstall /debug switches one time and then execute
it with /debug switch from IDE.
Let's create the client