Avoiding a VFP CursorAdapter Builder Error

If you create a form that contains a CursorAdapter that accesses remote data in the Data Environment, you might find that when you run the form the CursorAdapter cursor is not created. This can occur if you allow the Visual FoxPro CursorAdapter Builder to put code into the CursorAdapter cursor objectís Init event. (The CursorAdapter Builder also puts code into the AutoOpen event).

The problem is that the CursorAdapter Builder leaves out one important line of code - the line that places a connection handle in the DataSource property of the CursorAdapter. Without the connection handle in the DataSource property, the remote data cannot be accessed and the cursor cannot be created.

If you look at the Init code of a CursorAdapter class that you create through the VPME Data Builder, you will see that the line in question is there (This.DataSource = ...). However, when the Visual FoxPro CursorAdapter Builder inserts Init code into a CursorAdapterís cursor object, it blocks the correct Init code in the CursorAdapter class from being executed.

Since the correct code already exists in the CursorAdapter class, the solution to this problem is to not allow the VFP CursorAdapter Builder to put the problem code into the CursorAdapter cursor for a form. The Init and AutoOpen code is not needed in the cursor object because the code from the class will be used if none exists in the cursor (remember inheritance?).

Therfore, if you find code in the Init and AutoOpen events of a CursorAdapter cursor in the Data Environment of a form, remove it.

Tip Ė Donít Let the VFP CursorAdapter Builder Add Code: When you are in the process of adding a CursorAdapter to the Data Environment of a form using the Data Environment Builder, you must prevent the CursorAdapter Builder from putting code in the CursorAdapter's events. You can prevent the VFP CursorAdapter Builder from adding code by clicking the Cancel button whenever the CursorAdapter Builder is displayed. If you click the OK button instead, code will be added to the CursorAdapter's events, even if you do not make any changes to the CursorAdapter through the VFP CursorAdapter Builder.

Remember, if you end up with code in a CursorAdapter cursorís Init and AutoOpen events, you can simply remove it. Just make sure that the events are completely empty. They cannot even contain comments or spaces. Alternatively, if for some reason you need to leave the code in the Init event, you can simply add the missing line of code where it belongs (check the CursorAdapter class to see exactly where it goes).



Building Data: Fields