Freigeben über


UNBINDEVENTS() Function

You can use UNBINDEVENTS() to unbind, or detach, an event that was originally bound to a Visual FoxPro object using BINDEVENT(). To detach events from Component Object Model (COM) objects, use the EVENTHANDLER() function.

UNBINDEVENTS( oEventSource, cEvent, oEventHandler, cDelegate )

-or-

UNBINDEVENTS( oEventObject )

The following table describes the ways you can use UNBINDEVENTS().

Syntax Action
UNBINDEVENTS( oEventSource, cEvent, oEventHandler, cDelegate )
Unbinds a specific event from an event handler.
UNBINDEVENTS( oEventObject )
Unbinds all events associated with this object. This includes events that are bound to it as an event source and its delegate methods that serve as event handlers.

Parameters

  • oEventSource
    Specifies the event source, which must be a valid Visual FoxPro object.
  • oEventObject
    Specifies an object reference, which can be used as the event source or event handler.
  • cEvent
    Specifies the name of the event, method, or property you want to unbind.
  • oEventHandler
    Specifies the object that is handling the event.
  • cDelegate
    Specifies the delegate method handling the event for oEventHandler.

Return Values

Numeric data type. UNBINDEVENTS() returns the number of events that are unbound if unbinding succeeds. UNBINDEVENTS() returns a value of 0 if no events exist for unbinding. Visual FoxPro generates an error if UNBINDEVENTS() fails to unbind events that are available for unbinding.

Remarks

If an event is occurring, and UNBINDEVENTS() or the delegate method handling the event is called, the event and its delegate method finish running before UNBINDEVENTS() unbinds the event.

You can call the AEVENTS() function retrieve information about all the events and delegate methods attached to a particular object.

Example

The following example shows how to undo a BINDEVENTS( ) call that keeps the Class Browser positioned to the right side of the Visual FoxPro desktop, regardless of how the desktop is resized. UNBINDEVENTS( ) detaches the Resize event of the _SCREEN system variable from the object, oHandler:

PUBLIC oHandler
oHandler=NEWOBJECT("myhandler")
DO (_browser)
BINDEVENT(_SCREEN,"Resize",oHandler,"myresize")
UNBINDEVENTS(_SCREEN,"Resize",oHandler,"myresize")

DEFINE CLASS myhandler AS Session
   PROCEDURE myresize
   _obrowser.left = _SCREEN.Width - _obrowser.width
   RETURN
ENDDEFINE

See Also

Functions | Event Binding for Visual FoxPro Objects | BINDEVENT() Function | EVENTHANDLER( ) Function | RAISEEVENT() Function | AEVENTS() Function