Condividi tramite


Event Binding for COM Objects

You can bind events from Component Object Model (COM) objects to a Visual FoxPro object by using the EVENTHANDLER( ) function. For example, by binding an event from an ActiveX Data Object (ADO) recordset, you can run Visual FoxPro code when the record pointer moves around in the recordset. The EVENTHANDLER( ) function specifically handles binding events raised by COM objects and by the IConnectionPoint interface, which is part of COM.

However, Visual FoxPro does not support the raising events through the IConnectionPoint interface directly. In order to bind a COM event to a Visual FoxPro object, the object must implement the event interface of the COM object, an action referred to as tightly-coupled event handling, where both the event source and event sink objects are live when the event occurs. Event sinks are clients that bind to a connectable object because they receive events triggered by the connectable object.

Instead, COM+ Events, part of COM+ Services, provides the preferred strategy for handling events between COM components. COM+ Events sends and delivers event notifications between applications. Applications can send and receive notifications of events, such as the hiring of a new employee, a change in a stock price, or a drop in inventory level that requires restocking.

In the COM+ Events model, applications that send out event notifications act as event sources and are called publishers. Applications that receive event notifications are called subscribers. COM+ Events are often called loosely coupled events because publishers and subscribers do not possess any knowledge about each other and allow event subscribers to remain inactive until events occur. Instead, you define a set of events inside the scope of an event class, and this event class is installed in a COM+ application.

To use COM+ Events, you author an event class that implements one or more interfaces. Each interface defines a group of methods, which represents a set of events. You write subscriber components that implement these interfaces and respond to events when they occur. Finally, you write a publisher application to create objects from the event class and call various methods when the application is ready to fire events. The event service handles processing the method and delivering the events to every subscriber.

See Also

Event Binding for Objects | Event Binding for Visual FoxPro Objects | EVENTHANDLER( ) Function