Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CursorAdapters in VFP

Status
Not open for further replies.

ChuckFlowers

Technical User
Feb 26, 2011
2
US
I am having a problem in trying to use a 2nd CursorAdapter on a form. No problem using he first CA, but the second CA won't work. Any helpful hints ?
 
Won't work"

What exactly does not work?

a) you get an error message when adding the 2nd CA
b) 2nd CA does not create a cursor
c) 2nd CA does create an empty cursor
d) 2nd CA does query wrong data
e) ...
f) ...

There can be so many things "not working", what should we advise?
In general a second, third, fourth etc. CA will work exactly as a 1st, there is no general limit to one CA, as there is no limit for tables and views.

So maybe you simply just did something different. Open bot CAs in the designer and look for differences in the All tab.

Bye, Olaf.
 
...look for differences in the "All" tab of the properties window.

Bye, Olaf.
 
Using MySQL 5.1 on Windows 7 Home Premium, VFP SP2
DataEnvironment (DE) CursorAdapter (CA)

1. Build Form 1, use Form 1 DE, Table 1 in form DE as CA. Grid works fine.
2. Build Form 2, use Form 2 DE, Table 2 in form DE as CA. Grid works fine.
3. Build Form 3, use Form 3 DE, Table 1 in form DE as CA. Grid works fine.
Problem starts here:
Add Table 2 as CA to Form 3 above, place in 2 separate grids, not related.

Form won't run - Error message says:
Error loading file - record number 15. grdCursor2 <or one of its members>. ControlSource : Alias 'Cursor2' is not found.

Multiple attempts, same results - record number may vary.

I discarded the forms & re-started VFP to avoid any potential residual problem after every effort, etc.
No other classes or other code running, just the form.

So I tried a few other things.

4. Build Form 3, use Form 3 DE, Table 1 and Table 2 in form DE as CA's.
Only placed one grid based on Table 1 CA on on the form. Runs fine.

5. Removed grid based on Table 1 CA, placed grid based on Table 2 CA on the form.
Form won't run, similar error message.

6. Removed the Table 1 CA from the form DE, placed grid based on Table 2 on form.
Runs fine.

I have figured out a few more things.
I determined that using the DE to configure the connection.
If I do ALL connection configuration (carefully !) in each cursor, no problem.

So I can use CA's now. Just can't touch the DE.
But they are just so intimately involved.

And this will cause me more problems down the road until I figure out how to work it. I had planned to develop a DE class that would include CA's.

I came across this:
(from What's New in Visual FoxPro 8, page 134)

For a CursorAdapter instantiated in code, the Init event fires before all others, as you'd expect.

But for a CursorAdapter in the DataEnvironment of a form, the event order is different:

Event Order For a CursorAdapter in the DataEnvironment of a form:
DataEnvironment.OpenTables */* Is this right, does DataEnvironment.OpenTables fire before DataEnvironment.BeforeOpenTables ?
DataEnvironment.BeforeOpenTables */* OR should this line read as CursorAdapter.BeforeOpenTables ?
CursorAdapter.AutoOpen
CursorAdapter.BeforeCursorFill
CursorAdapter.CursorFill
CursorAdapter.AfterCursorFill
CursorAdapter.Init
DataEnvironment.Init



Thanks,

Chuck
 
It's true that the event order os OpenTables, BeforeOpentables, viewed from the event tracking/stack. ButOpenTables() first "line" of the native behaviour is calling BeforeOpenTables(), so still coe in BeforeOpenTables() runs first. You can check that by logging.

I don't have that book, but you can check the truth again by logging even better than by event tracking. Put DODEFAULT() and then a call to log in each event/method and from the log you'll then see which runs first. I'd need to experiment with that, before confirming or not. In my knowledge init() of a CA runs first.

To your reported error: What is record 15 of the form? If you USE form3.scx what is really in record 15? Is it the CA or is it the grid of the 2nd table?

As you connect to mysql, so how do you connect, if both CA share the same connection, do you make the connection outside of the CA before the first CA runs, or does each CA make his own connection?

Have you created the CA from scratch all by yourself or did you use the CA builder? CA builder also generates code.

Bye, Olaf.
 
1st experiment in regard to BeforeOpenTables() and OpenTables()

Putting "? sys(16)" into these method/event does print OpenTables before BeforeOPenTables.

Adding DODEFAULT before each ? sys(16) inverts the order and causes an error stating dataenvironement is already loaded.

I assume the dodefault() in opentables causes to load the dataenvironment. Having no NODEFAULT means that runs twice and thus the error.

At least the form runs fine with these methods:

Code:
? 'before dodefault '+Sys(16)
DoDefault()
? Sys(16)

Code:
? 'before dodefault '+Sys(16)
DoDefault()
? Sys(16)
NoDefault

order of output on the screen then is
1. before dodefault of opentables
2. before dodefault of beforeopentables
3. beforeopentables
4. opentables

This speaks for what I said initially, opentables is called first but the first thing it does in it's native code is calling beforeopentables. If you don't do DODEFAULT() that's still true, but code you add to opentables() runs before the native opentables() code, therefor for own code, opentables comes before beforeopentables().

If you make the mysql connection in the DE code section you can put that in both BeforeOpenTables() and OpenTables(). CA or any other visual component in the DE comes afterwards. DE init comes last.

In regard of CA event order I need to experiment a little further. Unfortunately that has to wait, but you've got the ideas to test yourself.

Bye, Olaf.
 
Now in regard to CA:

First of all, I did two CAs with a MYSQL connection (using MySQL 5.1 ODBC driver) working ok in the DE of a scx from. both cursors are created and shown in a grid.

In regard to event order:

a) AutoOpen is no method or event but a booleand property. If you want to CA to automatically query data you set this .t.

b) Putting "? sys(16)" into each of the mentioned methods/events I get

1. form.CA.init()
2. form.CA.cursorfill()
3. form.CA.beforecursorfill()
4. form.CA.aftercursorfill()
5. form1.CA.init()

So in fact CA init() runs last, but also first. Notice the difference "form" in step 1 vs "form1" in step 5. My interpretation of it is, that after the form inited and got it's name form1, CA init is rerun.

In regard of cursorfill running before beforecursorfill, the same reasoning for opentables and beforeopentables applies: beforecursorfill is called from cursrofill. And that makes sense, if you don't have autoopen = .t., you call cursorfill() to fill the cursor, and that first calls beforecursorfill().

Overall I'm having no problem with 2 CAs, so what are you doing, how are you connecting to mysql?

I'd copy the form, and then in the copy remove both grids, to see how the CAs alone query data. Start the form then open the datasession window.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top