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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a public cursor?

Status
Not open for further replies.

MarnickBolle

Programmer
Feb 7, 2003
17
BE
In the startup mainprog.prg from my VFP-project I create a cursor like this:

=sqlexec(gnConHandle,"select field from table","curCursor")

Is it possible to use this cursor over the whole project so that anywhere (in every form etc...) I can reach the data from that "public cursor"?

If this is impossible, it looks like I have to store the fields in a public array, but is this really necessary???
 
MarnickBolle,

If you create the cursor at the start of your main program, it will be visible throughout the application, except in forms that have their own data session.

If your forms do have their own data sessions, you will have to temporarily switch back to the original data session to access the cursor. To do so, save the current data session ID in a variable, using SET("DATASESSION"), then switch to the original data session (using SET DATASESSION), access the cursor, and switch back to the saved data session.

I would suggest that you wrap the above into a function that you can call from anywhwere. You could write the function so that it accepts a field name as a parameter, and returns the contents of that field. That way, if you ever decide to switch to a different way of storing the data, such as a public array, you'll only have to change the one function.

Hope this helps.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top