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. There are three versions of the syntax.
UNBINDEVENTS(oEventSource, cEvent, oEventHandler, cDelegate)
UNBINDEVENTS(hWnd [, nMessage])
- Specifies the event source, which must be a valid Visual FoxPro object.
- Specifies an object reference, which can be used as the event source or event handler.
- Specifies the name of the event, method, or property you want to unbind.
- Specifies the object that is handling the event.
- Specifies the delegate method handling the event for oEventHandler.
- Specifies the integer handle of the window for which events are unbound. If hWnd is 0, all hWnds are unbound. If the nMessage parameter isn't included, then all Windows message bindings for the window handle hWnd are unbound.
- Specifies a valid Windows message (Win Msg) that is unbound. See MSDN (the Microsoft Developer Network) for information about Windows messages.
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.
The following table describes the ways you can use UNBINDEVENTS(В ).
Unbinds a specific event from an event handler.
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.
Unbinds all or specific Windows Message (Win Msg) events.
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.
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,
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
ReferenceSYS(2325) - WCLIENTWINDOW from Visual FoxPro WHANDLE
SYS(2326) - WHANDLE from a Window's hWnd
SYS(2327) - Window's hWnd from Visual FoxPro WHANDLE
Event Binding for Visual FoxPro Objects
AEVENTS( ) Function
BINDEVENT(В ) Function
EVENTHANDLER( ) Function
RAISEEVENT(В ) Function