VFP 9 TIP: Cursors accessing remote data

The place where ProMatrix posts coding tips and fixes. Read only.

VFP 9 TIP: Cursors accessing remote data

Postby JessicaLawson » Sun Jun 13, 2010 5:33 pm

VFP 9 TIP: Cursor not created when using CA in DE that accesses remote data

If you have created a form that contains a cursoradapter in the DE that accesses remote data, you
might have found that when you run the form the CA cursor does not get created. This can occur if
you allow the CA Builder to put code into the CA's Init event (it also puts code into the AutoOpen
event). What happens is that the CA Builder leaves out one important line, the line that places a
connection handle in the DataSource property of the CA. 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 the CAs you have created through the Data Builder you will see that
the line in question is there (This.DataSource = ...). Since the correct code exists in the CA
class, the solution to the problem is to not allow the CA Builder to put the problem code into the
CA events in the form. The Init and AutoOpen code is not needed in the form anyway, since the code
from the class will be used if none exists in the form (remember inheritance?). So, if there is code
in the Init and AutoOpen events of a CA in the DE of a form, remove it. If you are in the process of
adding a CA to the DE of a form using the DE Builder you can prevent the CA Builder from putting
code in the CA's events if you follow these steps:

1. On the Cursors page of the DE Builder click the Add button.
2. On the Open dialog find the CA class to be added and click the OK button.
3. The CA Builder is automatically brought up. Click the Cancel button.
4. Back in the DE Builder click the OK button to add the CA to the DE.

The key to preventing the code from being put into the CA events is clicking the Cancel button in
step 3. If you click the OK button instead, code will be added to the CA's events, even if you do
not make any changes to the CA through the CA Builder.

Remember, if you end up with code in the 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 CA class to see exactly where it goes).
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Return to ProMatrix Library

Who is online

Users browsing this forum: No registered users and 1 guest