CLR Extender Reference

CLRBindEvent Function

Description »

Bind a .NET Event to a VFP Handler.

CLRBindEvent(oNetEventSource , cNetEvent , oVFPEventHandler , cVFPDelegate  [, lIndirect])

Parameters

oNetEventSource
The .NET object which exposes an Event to be handled.
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 to which you want to bind.
Note:

The .NET Event model is more limited than the powerful Event Model of VFP. You can bind only to .NET Members which are actual Events, that is, you CAN'T bind to a property or method of oNetEventSource.

oVFPEventHandler
The VFP object which would handle the event. It can be any object to which you want to bind.
Note:

Be aware that this object will have it's reference count incremented, so if you bind to an object in a form, the form could not be closed until there are not references to the contained objects. To avoid this situation use the lIndirect = .t. argument.

cVFPDelegate
The name of the Method in oVFPEventHandler that will handle the event.
Note:

This method must have the same number of parameters as the parameters exposed by cNetEvent, otherwise if you include less parameters an error will be raised when the Method is called.

[, lIndirect]
Use this parameter to create an indirect binding, preventing situations where the parent form can't be closed because of references to contained controls. CLR Extender, then creates a binding to the control through the form, which in VFP can be closed even when there are reference to it (as opposed when the references are to contained controls).

Return Value

Numeric. 1 indicates a successful binding, 0 a failure.

Example »

The following example Creates a .NET form with a button contained and then binds the click event to a VFP Object.

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)
ENDDEFINE
Remarks »

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

= CLRBindEvent(oNetControl, "click", oVFPHandler, "ClickHandler")

- Or to create an indirect binding:

= CLRBindEvent(oNetControl, "click", oVFPHandler, "ClickHandler", .T.)
Other Resources »

CLRUnBindEvent function


Send comments about this topic to eTecnologia.net.