Download Delphi 7 Developers Guide

Transcript
Generating events under COM+
When you exit, the wizard creates a project containing a type library that defines
your event object and its interface. Use the Type Library editor to define the methods
of that interface. These methods are the event handlers that clients implement to
respond to events.
The Event object project includes the project file, _ATL unit to import the ATL
template classes, and the _TLB unit to define the type library information. It does not
include an implementation unit, however, because COM+ event objects have no
implementation. The implementation of the interface is the responsibility of the
client. When your server object calls a COM+ event object, COM+ intercepts the call
and dispatches it to registered clients. Because COM+ event objects require no
implementation object, all you need to do after defining the object’s interface in the Type
Library editor is compile the project and install it with COM+
COM+ places certain restrictions on the interfaces of event objects. The interface you
define in the Type Library editor for your event object must obey the following rules:
•
•
•
•
The event object’s interface must derive from IDispatch.
All method names must be unique across all interfaces of the event object.
All methods on the event object’s interface must return an HRESULT value.
The modifier for all parameters of methods must be blank.
Using the COM+ Event Subscription object wizard
You can create the subscriber component using Delphi’s COM+ Subscription Object
wizard. To bring up the wizard,
1 Choose File|New|Other.
2 Select the tab labeled ActiveX.
3 Double-click the COM+ Subscription Object icon.
In the wizard dialog, enter the name of the class that will implement the event
interface. Choose the threading model from the combo box. In the Interface field, you
can type the name of your event interface, or click on the Browse button to bring up a
list of all event classes currently installed in the COM+ Catalog. The COM+ Event
Interface Selection dialog also contains a browse button. You can use this button to
search for and select a type library containing the event interface. When you select an
existing event class (or type library), the wizard will give you the option of
automatically implementing the interface supported by that event class. If you check
the Implement Existing Interface checkbox, the wizard will automatically stub out
each method in the interface for you. To complete the wizard, enter a brief
description of your event subscriber component, and click on OK.
46-22
Developer’s Guide