EventHandler( ) (Función)
Vincula un evento de servidor COM a métodos de interfaz implementados en un objeto de Visual FoxPro.
EventHandler(oCOMObject, oVFPObject [, lUnbind])
Valores devueltos
Logical. (.T.) si tiene éxito.
Parámetros
- oCOMObject
Especifica la referencia del objeto al objeto cuyos eventos deben vincularse. - oVFPObject
Especifica la referencia del objeto al objeto de Visual FoxPro que contiene los métodos definidos por el usuario, que se corresponde con los eventos de objeto COM correspondientes. La clase debe implementar la interfaz de eventos para el objeto COM particular que se pasa en el primer parámetro. Por ejemplo, debe implementar la interfaz RecordsetEvents para vincular un objeto de conjunto de registros ADO. - lUnbind
Visual FoxPro detiene automáticamente el control de eventos cuando uno de los objetos sale del alcance. Al pasar este parámetro, puede detener el control de eventos mientras ambos objetos permanecen en el alcance.
Observaciones
oCOMObject debe ser un objeto COM válido.
Puede vincular un solo objeto COM a varios objetos de Visual FoxPro o bien puede vincular varios objetos COM al mismo objeto de Visual FoxPro.
El control de eventos se desvincula automáticamente cuando se libera el objeto COM o de Visual FoxPro. Puede llamar explícitamente a la función EventHandler( ) y pasar el parámetro lUnbind para desvincular objetos sin liberar referencias de objetos.
Ejemplo
LOCAL oEvents
LOCAL oRS AS adodb.recordset
LOCAL oConn AS adodb.Connection
oEvents = NEWOBJECT("myclass")
oConn = NEWOBJECT("adodb.connection")
oConn.Provider="MSDASQL"
* Make sure to set the SourceDB property
* below to your TESTDATA location.
oConn.ConnectionString="DSN=Visual FoxPro Database;" + ;
"SourceType=DBC; SourceDB=D:\VFP\DATA\TESTDATA.DBC"
oConn.Open
oRS = oConn.Execute("select * from customer")
? EVENTHANDLER(oRS, oEvents)
?
? PADR(oRS.Fields(0).Value,20)
? EVENTHANDLER (oRS, oEvents, .T.)
oRS.MoveNext
? PADR(oRS.Fields(0).Value,20)
oRS.MoveNext
CLEAR all
RETURN
DEFINE CLASS myclass AS session
IMPLEMENTS RecordsetEvents IN "adodb.recordset"
PROCEDURE Recordsetevents_WillChangeField(cFields AS Number @, Fields AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_FieldChangeComplete(cFields AS Number @, Fields AS VARIANT @, pError AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_WillChangeRecord(adReason AS VARIANT @, cRecords AS Number @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_RecordChangeComplete(adReason AS VARIANT @, cRecords AS Number @, pError AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_WillChangeRecordset(adReason AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
?adreason,adstatus,precordset.recordcount
PROCEDURE Recordsetevents_RecordsetChangeComplete(adReason AS VARIANT @, pError AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_WillMove(adReason AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_MoveComplete(adReason AS VARIANT @, pError AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_EndOfRecordset(fMoreData AS LOGICAL @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_FetchProgress(Progress AS Number @, MaxProgress AS Number @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
PROCEDURE Recordsetevents_FetchComplete(pError AS VARIANT @, adStatus AS VARIANT @, pRecordset AS VARIANT @) AS VARIANT
? " "+program() + ' ' + TRANSFORM(DATETIME())
ENDDEFINE