Products:

- SvCom
- Shell+
- PerfUtils

Download:

- SvCom
- Shell+
- PerfUtils

Ordering:

- Order now

Support:

- Contact directly


Embarcadero Technology Partner

 
    Adding COM-object methods  

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 it.

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;
    U: IUnknown;
    E: IComObjectWithEventsEvents;
begin
{$IFDEF DELPHI5ORHIGHER}
    with FConnectionPoint.SinkList do
    begin
        for i:=0 to Count-1 do
        begin
            U:=IUnknown(Items[i]);
            if not Assigned(U) then continue;
            E:=U as IComObjectWithEventsEvents;
            E.HandleEventNotification('Event is raised with message: '+Text);
        end;
    end;
{$ELSE}
    if Assigned(FEvents) then
        FEvents.HandleEventNotification('Event is raised with message: '+Text);
{$ENDIF}
end;

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 HandleEventNotification 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 application now...

<< . index . 1 . 2 . 3 . 4 . >>
SvCom links:

- Overview
- Download
- Purchase
- FAQ
- Tutorial
- What's new
- For registered users
- Support

Copyright:

© 1998-2003. Alexey Dynnikov
© 2003-2016. ALDYN Software
© Design: Adonis i-cafe.