CLR Extender Reference

CLRUnBindEvents Function

Description »

UnBinds a .NET Event from a VFP Handler.

CLRUnBindEvents(oNetEventSource [, cNetEvent , oVFPEventHandler , cVFPDelegate] )

Parameters

oNetEventSource
The .NET object with the event to Unbind.
Note:

You can use the Assembly Browser to see the events exposed by an object. Also check the class documentation to see additional info about the parameters passed to the event handler.

cNetEvent
Specifies the name of the event currently subscribed and which will be UnBinded.
oVFPEventHandler
The VFP object that is handling the event.
cVFPDelegate
The name of the Method in oVFPEventHandler which actually is handling the event.

Return Value

Numeric. Returns the number of UnBinded events.

Example »

The following example creates a .NET form with a button contained and then binds the click event to a VFP Object, when you click in the .NET button the ClickHandler method is called and the event is UnBinded, after that, further clicks are not handled.

LOCAL oForm, oButton, oHandler
* Creates the form and a Button on it
oForm = CLRCreateObject("system::windows::forms::form")
oButton = CLRCreateObject("system::windows::forms::Button")
oButton.AutoSize = .T.
oButton.Text = "Click me to see the event running in VFP"
oForm.Controls.Add(m.oButton)
oHandler = CREATEOBJECT("vfpSampleHandler")
= CLRBindEvent(oButton, "click", oHandler, "ClickHandler")
oForm.Show()  && Use Ctrl+Tab to switch to the .NET form


* This is a sample class which can handle the event
DEFINE CLASS VFPSampleHandler AS Custom

	* It's very important to have the number of parameters equals or greater to the 
	* number of parameters on the .NET Event
	* Most .NET events require two parameters: oSource and oEventArgs
	* Check the documentation to be sure
	*
	PROCEDURE ClickHandler
	LPARAMETERS oSource, oEventArgs  && Usually this are the parameters needed
	WAIT WINDOW "I am handling a .NET Event" NOWAIT
	= MESSAGEBOX("The source is a :"+oSource.GetType().FullName)
	? CLRUnbindEvents(m.oSource,"click",this,"clickhandler")
ENDDEFINE
Remarks »

CLRUnBindEvent gives you an easy, "VFP Style" way to handle .NET Events.

* Unbinds only a specific event - event handler
* Should return 1
= CLRUnBindEvents(oNetControl, "click", oVFPHandler, "ClickHandler")

- Or to create an indirect binding:

= CLRUnBindEvents(oNetControl)  && Unbinds all the events of oNetControl
Other Resources »

CLRBindEvent function


Send comments about this topic to eTecnologia.net.