Discussion:
Hard to Reproduce Spinbox Error
(too old to reply)
Ken Mayer [dBVIPS]
2008-09-19 22:30:17 UTC
Permalink
I can only reproduce the problem I am experiencing in a really complex
for ... or at least, I cannot reduce it down to a form that I can
reproduce it, but ...

Spinbox -- onChange event handler. IF: you enter the value by typing it
into the spinbox, then tab off the control, this event does not always
fire. If you use the buttons to change the value in the control, the
event fires. If you click somewhere else on the form after changing the
value by typing, it fires. But in this one form, there are occaisions
where it does not fire if you tab off the control.

The workaround is to call the event handler for onChange in the spinbox
control's onLostFocus event handler, which seems to work.

If I could trim it down to something smaller, I would, but so far, my
attempts are not working.

To test it in the complex form, I added code at the beginning of the
onChange event code that output:
? form.activecontrol.name
? "QtySB_onChange() fired ..."

And when tabbing off the control (after entering a value by typing it,
rather than using the buttons of the spinbox) this did not appear in the
output pane of the Command Window, but if I clicked somewhere else, it
did; or if I used the buttons to change the value.

Has anyone else seen anything like this?

Ken M.
--
/(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
Ronnie MacGregor
2008-09-20 07:39:45 UTC
Permalink
On Fri, 19 Sep 2008 15:30:17 -0700
Post by Ken Mayer [dBVIPS]
And when tabbing off the control (after entering a value by typing it,
rather than using the buttons of the spinbox) this did not appear in the
output pane of the Command Window, but if I clicked somewhere else, it
did;
Morning Ken

Have you checked to see if the spinbox actually is losing focus ?

No validation code that might keep focus there ?
--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk
Ken Mayer [dBVIPS]
2008-09-20 13:53:21 UTC
Permalink
Post by Ronnie MacGregor
On Fri, 19 Sep 2008 15:30:17 -0700
Post by Ken Mayer [dBVIPS]
And when tabbing off the control (after entering a value by typing it,
rather than using the buttons of the spinbox) this did not appear in the
output pane of the Command Window, but if I clicked somewhere else, it
did;
Morning Ken
Have you checked to see if the spinbox actually is losing focus ?
No validation code that might keep focus there ?
There is no validation code -- for this particular field (Quantity
Ordered), there isn't a need -- using the spinbox I can give an
acceptable range. The problem is specifically tabbing off. It loses
focus properly: onLostFocus fires every time. It's the onChange event
that doesn't seem to, but only, as noted, if the value is changed using
the keyboard, and the user tabs off the field. My workaround is to use
onLostFocus to call the onChange code (which may cause that to fire more
than necessary, but at least it fires).

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
Jaime Escobal
2008-09-24 20:06:10 UTC
Permalink
I can confirm this bug too. I have that workaround in many several in my source code Has anybody any news about how to fix this?
Jaime Escobal
Ken Mayer [dBVIPS]
2008-09-24 21:33:10 UTC
Permalink
Can you reproduce it outside of a complex screen? I just don't know what
is causing it ... I mean, the onLostFocus workaround resolves it, but it
does fire any onChange event twice in the cases where the event fires
properly. Not a big deal for the two places I have had to work around
it, but ...

Ken
Post by Jaime Escobal
I can confirm this bug too. I have that workaround in many several in my source code Has anybody any news about how to fix this?
Jaime Escobal
--
/(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
Marty Kay
2008-09-25 14:44:25 UTC
Permalink
Hi Ken,
I can only reproduce the problem I am experiencing in a really complex for
... or at least, I cannot reduce it down to a form that I can reproduce it,
but ...
Spinbox -- onChange event handler. IF: you enter the value by typing it
into the spinbox, then tab off the control, this event does not always
fire. If you use the buttons to change the value in the control, the event
fires. If you click somewhere else on the form after changing the value by
typing, it fires. But in this one form, there are occaisions where it does
not fire if you tab off the control.
So far, I have not been able to reproduce this problem.
Any sample code you have would be appreciated.

- Marty -

Martin Kay
dataBased Intelligence, Inc.
Marty Kay
2008-09-25 14:58:57 UTC
Permalink
I just found QAID: 90 illustrating one case where spinbox onChange() does
not fire.
Here is the code from this QAID.

set data to
if file("spintest.dbf")
drop table "spintest.dbf"
endif

create table "spintest.dbf" ( date1 date, date2 date )
use spintest
appe blank
use
** END HEADER -- do not remove this line
//
// Generated on 03/07/2000
//
parameter bModal
local f
f = new spintestForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class spintestForm of FORM
with (this)
height = 10.3636
left = 49.8571
top = 5.9545
width = 57
text = ""
endwith


this.QUERY1 = new QUERY()
this.QUERY1.parent = this
with (this.QUERY1)
left = 19
top = 4
sql = "select * from spintest"
active = true
endwith




this.SPINBOX1 = new SPINBOX(this)
with (this.SPINBOX1)
onChange = class::SPINBOX1_ONCHANGE
valid = class::SPINBOX1_VALID
dataLink = form.query1.rowset.fields["date1"]
height = 1
left = 6.4286
top = 1.8182
width = 14.4286
endwith


function SPINBOX1_onChange
?program()
return

function SPINBOX1_valid
?program()
this.value := this.Value
return true
endclass


Note that the spinbox is datalinked to a date field AND SPINBOX1_valid
contains the line:
this.value := this.value.

If you remove this line than onChange fires as expected.

Are you doing anything like this?

- Marty -

Martin Kay
dataBased Intelligence, Inc.
Ken Mayer [dBVIPS]
2008-09-25 20:48:04 UTC
Permalink
Post by Marty Kay
I just found QAID: 90 illustrating one case where spinbox onChange() does
not fire.
Here is the code from this QAID.
set data to
if file("spintest.dbf")
drop table "spintest.dbf"
endif
create table "spintest.dbf" ( date1 date, date2 date )
use spintest
appe blank
use
** END HEADER -- do not remove this line
//
// Generated on 03/07/2000
//
parameter bModal
local f
f = new spintestForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class spintestForm of FORM
with (this)
height = 10.3636
left = 49.8571
top = 5.9545
width = 57
text = ""
endwith
this.QUERY1 = new QUERY()
this.QUERY1.parent = this
with (this.QUERY1)
left = 19
top = 4
sql = "select * from spintest"
active = true
endwith
this.SPINBOX1 = new SPINBOX(this)
with (this.SPINBOX1)
onChange = class::SPINBOX1_ONCHANGE
valid = class::SPINBOX1_VALID
dataLink = form.query1.rowset.fields["date1"]
height = 1
left = 6.4286
top = 1.8182
width = 14.4286
endwith
function SPINBOX1_onChange
?program()
return
function SPINBOX1_valid
?program()
this.value := this.Value
return true
endclass
Note that the spinbox is datalinked to a date field AND SPINBOX1_valid
this.value := this.value.
If you remove this line than onChange fires as expected.
Are you doing anything like this?
Mine is a custom spinbox, datalinked to a numeric field in a table. Very
specifically: clicking OFF the field anywhere on the form, the onChange
event fires after making a change; tabbing OFF the field anywhere in the
form, after keyboarding a change (just using the keyboard) the onChange
does not fire. I don't think these are the same issue.

The problem is, I tried to narrow it down, and give a sample, but
couldn't. It happens on two forms, but they have a LOT going on.

The control's constructor is:

this.QTYSB = new KMCUSTSPINBOX(this)
with (this.QTYSB)
onLostFocus = class::QTYSB_ONLOSTFOCUS
onChange = class::QTYSB_ONCHANGE
dataLink = form.quotes2.rowset.fields["qsold"]
height = 19.0
left = 30.0
top = 416.0
width = 45.0
picture = "9999"
rangeRequired = false
endwith

And the event code is:

function QTYSB_onChange
// Make sure the Charges field is updated:
local oFld
oFld = form.quotes2.rowset.fields
oFld["QSOLD"].value := this.value
form.quotes2.rowset.save()
oFld["Charges"].value := ( oFld["QSOLD"].value *
oFld["PricEach"].value )

// update BackOrder if not Direct Ship:
if oFld["CODE"].lookupRowset.fields[1].value # "K"
if oFld["ONHAND"].value < oFld["QSOLD"].value
oFld["BackOrder"].value := true
else
oFld["BackOrder"].value := false
endif
endif
form.LineItemGrid.refresh()

// update the Running Totals:
class::RunningTotals()
return

// this is my workaround code:
function QTYSB_onLostFocus
// ensure that we do the correct calculations:
this.onChange()
return


I don't know if that will help.

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...