Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with ADO WillChangeField event and errortrapping
Message
From
24/10/2000 09:46:13
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Client/server
Title:
Problem with ADO WillChangeField event and errortrapping
Miscellaneous
Thread ID:
00433429
Message ID:
00433429
Views:
57
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
Next
Reply
Map
View

Click here to load this message in the networking platform