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

How to properly use cursor? 3

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
I have a form that has 4pages, three of these pages uses the cursor initialized in the procedure init… is it ok to use three different cursor in the three pages? (The cursor used by the three pages content are just names…) thanks in advanced…
 
Once you have created a cursor, you can use it anywhere you like. It will be available in any form, or on any page of a pageframe, for as long as the cursor is open. You don't need to do anything special to achieve that.

(One exception to the above: you can only use the cursor in the data session in which it is created. But I doubt if that will be an issue for you, Mandy.)

And, yes, you can have three different cursors open at the same time - provided, of course, that they have different names.

Does that answer your question?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes Mike you have answered my question… i have asked this because sometimes i receive an error “cannot access cursor…” since i cannot locate what could be the error… so im thinking of separate cursors… thanks Mike…
 
My experience is that "cannot access cursor" is an error you get from combos and lists when you've closed the table or cursor they're based on.

Tamar
 
Yes Tamar that's what I'm thinking too... but in my application I didn't see closing of the cursor... maybe I have just overlooked it... I'll still try to find where in the code I have closed the cursor.... Thank Tamar...
 
It's easy to overlook that opening another table can close a table or cursor of the currently selected workarea. Which means, it can be an code that opens another table that accidentally closes the cursor the control still needs.

Chriss
 
If you create a cursor in the Activate or Init event of a page, for example, you redo it again and again, and reusing the name would also be a reason you close the cursor at the same time you recreate it.

That's also the tricky part about repeated parts of a form UI, if you have a combobox for picking from a list stored in a table, for example, and need it in several places on a form, on several pages of a pageframe, using the same name means you also have the same selected record in all of them once a user picks an item in one of the comboboxes. To have separate picks you also need separate cursor names.

Chriss
 
Use the Debugger to find out whether you've closed the relevant table/cursor. In the Watch window, put:

USED('TheAliasInQuestion')

and then double-click in the margin to set a breakpoint. You'll see a red dot there.

Then, when you run your code, the breakpoint will fire any time the value the relevant alias is opened or closed.

Tamar
 
Thank you Chriss... I'll try it TamarGranor...Thank you...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top