Discussion:
Filter a rowset, onNavigate fires in a loop ...
(too old to reply)
Ken Mayer [dBVIPS]
2008-11-05 00:34:20 UTC
Permalink
Has anyone seen this? If you filter a rowset (at least if I do), I am
seeing the onNavigate event fire in a loop, causing a "Too many nested
DO/UDF" error ...

This is rather irritating, as you might imagine.

The code in the rowset's onNavigate is updating some text controls on
the form in use, and I need those to be accurate for just the currently
selected record. However, it appears to be doing this for every row in
the filter (although I am not 100% sure).

Any suggestions? Ideas?

The form is complex and relies on, among other things, proprietary data,
and custom classes and ... but I've never seen this behavior before.

TIA --

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Ken Mayer [dBVIPS]
2008-11-05 05:39:35 UTC
Permalink
Post by Ken Mayer [dBVIPS]
Has anyone seen this? If you filter a rowset (at least if I do), I am
seeing the onNavigate event fire in a loop, causing a "Too many nested
DO/UDF" error ...
This is rather irritating, as you might imagine.
The code in the rowset's onNavigate is updating some text controls on
the form in use, and I need those to be accurate for just the currently
selected record. However, it appears to be doing this for every row in
the filter (although I am not 100% sure).
Any suggestions? Ideas?
The form is complex and relies on, among other things, proprietary data,
and custom classes and ... but I've never seen this behavior before.
---

For what it's worth, it is looking like it might be a calculated field
that is causing this, although I'm not real sure. Whatever is causing
it, it is making me crazy. Sigh.

More as I dig into it (tomorrow).

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
*Lysander*
2008-11-05 06:52:02 UTC
Permalink
Post by Ken Mayer [dBVIPS]
For what it's worth, it is looking like it might be a calculated field
that is causing this, although I'm not real sure. Whatever is causing
it, it is making me crazy. Sigh.
More as I dig into it (tomorrow).
Does it happen ... when? Exactly when setting the filter?

You could try a setrange for a different approach just to see.

In general, I always found it a good idea to manually de-activate such
event-handlers as OnNavigate before reconstructing/rebuilding a rowset
and then activating it again.

TheForm.TheQuery.RowSet.OnNavigate = {;}
// do your re-filtering
TheForm.TheQuery.RowSet.OnNavigate = class::TheQueryRowSet_OnNavigate


Also it will be good to test if there is at least one row after
filtering, and then to call the event handler one time manually.

This is by far more performant than keeping the event active and it
might save you from what you just experience with that form.
Ken Mayer [dBVIPS]
2008-11-05 23:15:55 UTC
Permalink
Post by *Lysander*
Does it happen ... when? Exactly when setting the filter?
Yes. Or when I issue a "from.rowset.first()".
Post by *Lysander*
You could try a setrange for a different approach just to see.
I can't use setRange for this. The field is not in the index ...
Post by *Lysander*
In general, I always found it a good idea to manually de-activate such
event-handlers as OnNavigate before reconstructing/rebuilding a rowset
and then activating it again.
TheForm.TheQuery.RowSet.OnNavigate = {;}
// do your re-filtering
TheForm.TheQuery.RowSet.OnNavigate = class::TheQueryRowSet_OnNavigate
Hmm. I will have to look at trying that. The form this is based on does
things rather differently, and the code has never given any trouble, but
it's going straight to a specific record ... not bringing up a filtered
rowset (actually it is using a range, now that I think on it --
different form, different requirements).

Thanks for the idea ...

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Bruce Beacham
2008-11-05 13:48:15 UTC
Permalink
Post by Ken Mayer [dBVIPS]
Has anyone seen this? If you filter a rowset (at least if I do), I am
seeing the onNavigate event fire in a loop, causing a "Too many nested
DO/UDF" error ...
Any suggestions? Ideas?
I don't see how the filter is relevant to this problem, although I think
it would be to the efficiency of the app.

ISTM that the "Too many nested DO/UDF" error will be caused by something
_else_ triggering the onNavigate code, for the _same_ row, in a loop.
Each row navigation event will trigger just one call to the
onNavigate, which will then exit, so your intended navigation isn't the
reason for this problem.

So perhaps a very close study of the code in the onNavigate handler will
reveal such a call.

How about putting SET STEP ON in the onNavigate code and see how it gets
called (after the first, legitimate, call)?


Bruce Beacham
Ken Mayer [dBVIPS]
2008-11-05 23:16:53 UTC
Permalink
Post by Bruce Beacham
Post by Ken Mayer [dBVIPS]
Has anyone seen this? If you filter a rowset (at least if I do), I am
seeing the onNavigate event fire in a loop, causing a "Too many nested
DO/UDF" error ...
Any suggestions? Ideas?
I don't see how the filter is relevant to this problem, although I think
it would be to the efficiency of the app.
ISTM that the "Too many nested DO/UDF" error will be caused by something
_else_ triggering the onNavigate code, for the _same_ row, in a loop.
Each row navigation event will trigger just one call to the onNavigate,
which will then exit, so your intended navigation isn't the reason for
this problem.
So perhaps a very close study of the code in the onNavigate handler will
reveal such a call.
How about putting SET STEP ON in the onNavigate code and see how it gets
called (after the first, legitimate, call)?
All that's happening in the onNavigate is looping through a set of
fields and changing field controls ... no navigation is being fired.
That's the frustrating thing.

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Ken Mayer [dBVIPS]
2008-11-05 23:27:19 UTC
Permalink
Okay, I suddenly realized where the problem was -- I am setting the
filter using a combobox -- allowing the user to select a supplier to
filter the data on. The combobox is *not* dataLinked to anything, and
uses an array for the dataSource, so it should *not* be firing like
this, but the code loops when I select a supplier from the list. The
Suppliers1 query/rowset ... hmm ... it's being used in a lookup. Argh.

I may have just solved my problem, and need to put a second instance of
the query on the form (easy enough -- it's a small table) -- I think
that what is happening is the lookup value is changing and that's
causing some odd things ... weird. I'll be back.



function SUPPLIERFILTER_CB_onChange
// we're going to filter this thing based on
// what is selected, or in one case, clear the filter ...
? "Combobox onChange event handler"
private cVal, cCode, cOnNav
cVal = this.value.rightTrim()

// if "All Suppliers", then clear out the filter:
if cVal == form.SupplierList[1] // "All Suppliers"
form.rowset.clearFilter()
else
form.suppliers1.rowset.applyLocate( [Supplier=']+cVal+['] )
cCode = form.Suppliers1.rowset.fields["SupplierCode"].value
cOnNav = form.rowset.onNavigate
? cOnNav
form.rowset.onNavigate = null
form.rowset.filter := [FREEZE=']+cCode+[']
form.rowset.onNavigate = cOnNav
endif
// first row in new filter:
// form.rowset.first()

form.kmSeeker1.setFocus()
form.kmSeeker1.setFocus()
form.kmSeeker1.setFocus()
return
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Ken Mayer [dBVIPS]
2008-11-06 00:25:01 UTC
Permalink
For what it's worth, my solution was to remove the calculated field that
was causing at least part of the problem (and remove the explicit
navigate -- the call to the rowset's first() method), and not display it
in the grid. I have an entryfield that the user can see the value in,
and I am just calling the code as needed. It seems to work, and pretty
quick. This was a bizarre problem. I am sure there's some underlying
issue here that I am missing, but at this point, I have something I can
hand off to my client that does what he needs, I think (I hope!), and
... we'll see.

Thanks all for the help, and the use as a sounding board as I worked
through this thing.

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Ken Mayer [dBVIPS]
2008-11-06 00:06:29 UTC
Permalink
Post by Ken Mayer [dBVIPS]
Okay, I suddenly realized where the problem was -- I am setting the
filter using a combobox -- allowing the user to select a supplier to
filter the data on. The combobox is *not* dataLinked to anything, and
uses an array for the dataSource, so it should *not* be firing like
this, but the code loops when I select a supplier from the list. The
Suppliers1 query/rowset ... hmm ... it's being used in a lookup. Argh.
I may have just solved my problem, and need to put a second instance of
the query on the form (easy enough -- it's a small table) -- I think
that what is happening is the lookup value is changing and that's
causing some odd things ... weird. I'll be back.
That didn't solve it. I am getting close, but I am still at a loss. It
appears that certain code which does no navigation in the main form
(used specifically to determine a markup price) is causing the loop in a
calculated field. However, taking the calculated field out, and just
causing the code to fire and update an entryfield sort of works, it's
not 100% accurate, as it isn't showing the value for the very first
field in the filtered rowset. This is getting weirder and weirder.

If I uncomment this line:

// form.rowset.first()

in the combobox onChange, I go into a loop. If I don't, the data seems
okay, but the first row's value for the calculation is not updated (even
if I add:

form.MFRListEF_onLostFocus()

Into the code, which causes the event handler to fire that updates the
entryfield ...

Heartburn city, I tell you.

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Loading...