Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with ADO WillChangeField event and errortrapping
Message
From
25/10/2000 02:21:45
 
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00433429
Message ID:
00433924
Views:
13
Thanks Vlad!

You are right, it works fine when I use 'ON ERROR'.

Although I think it is a bit strange. In a good object model I would expect the Error event to always be fired when an error occurs. Especially when you work in an n-tier solution where you want to distribute the error to the UI.

/Peter

>Hi!
>
>Looks like Error event should be defined somewhere in the VFPCOM.DLL ;)
>
>Try to use 'ON ERROR' command to define error handler.
>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform