Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with ADO WillChangeField event and errortrapping
Message
De
24/10/2000 09:46:13
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Problem with ADO WillChangeField event and errortrapping
Divers
Thread ID:
00433429
Message ID:
00433429
Vues:
58
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
Fil
Voir

Click here to load this message in the networking platform