Information générale
Titre:
Problem with ADO WillChangeField event and errortrapping
Hi all!
I have a problem with the ADO event WillChangeField and errortrapping in VFP6.
I have created a class in VFP6 in which I have implemented the RecordSet events with the method BindEvents in VFPCOM.DLL.
When the WillChangeField event fires I cancel the field change by setting the parameter adStatus to 4 (adStatusCancel). When I do this Foxpro generates an error dialog with the error; OLE IDispatch exception code 0 from provider: Operation was canceled... This is ok because I assume the error comes from the recordset because I canceled the field change. To trap the error I add the Error event to my class, but I can't get it to fire.
What am I doing wrong? How can I intercept the error so it doesn't show on the screen?
Code sample:
loVfpCom = CREATEOBJECT("vfpcom.comutil")
loConnection = CREATEOBJECT("ADODB.Connection.2.5")
loConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=server;Initial Catalog=data;User ID=sa"
loConnection.Open()
loRecordSet = CREATEOBJECT("ADODB.Recordset")
loRecordSet.ActiveConnection = loConnection
loRecordSet.CursorType = 1 && adOpenKeySet
loRecordSet.CursorLocation = 3 && adUseClient
loRecordSet.LockType = 4 && adLockBatchOptimistic
loRecordSet.Source = "SELECT * FROM table"
loRecordSet.Open()
loObject = CREATEOBJECT("MyRecordSet")
loVfpCom.BindEvents(loRecordSet, loObject)
loRecordSet.MoveFirst()
loRecordSet.Fields(1).Value = "Test"
DEFINE CLASS MyRecordSet AS Custom
PROCEDURE WillChangeField(cFields, Fields, adStatus, pRecordset)
adStatus = 4 && adStatusCancel
ENDPROC
PROCEDURE Error(tnError, tcMethod, tnLine)
ACTIVATE SCREEN
?tnError, MESSAGE(), tcMethod, tnLine
ENDPROC
ENDDEFINE
TIA
/Peter
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement