Page 1 of 3
Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 7:15 am
by Rathinagiri
Please consider this sample
Code: Select all
# include "hmg.ch"
function main
private cStr := ""
private cStr1 := ""
use master
cStr := master->name
cStr1 := alltrim(master->name)
close all
define window Form1 at 0,0 width 300 height 200 main
define textbox t1
row 10
col 10
width 100
on change msginfo("TextBox 1 Changed")
end textbox
define textbox t2
row 40
col 10
width 100
on change msginfo("TextBox 2 Changed")
end textbox
define button b1
row 70
col 10
caption "Click me"
action (form1.t1.value := cStr,form1.t2.value := cStr1)
end button
end window
form1.center
form1.activate
return nil
Whenever we click the button, first textbox on change event is fired. Second textbox on change event is fired only once.
This happens only for the character type field values.
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 9:25 am
by esgici
Hi Rathi
I couldn't see the problem, in my machine everything is right
( XP SP-2 )
Regards
--
Esgici
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 9:46 am
by Rathinagiri
I too have XP-SP-2
How many times you have clicked the button? Can you please upload the exe file?!
Or test the attached file with the dbf file.
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 10:19 am
by Czarny_Pijar
After some researches I see it's a "space-sign" related behaviour.
As you can see, I tried to work around it, but without success.
Code: Select all
# include "hmg.ch"
function main
define window Form1 at 0,0 width 300 height 200 main
define textbox t1
row 10
col 10
width 150
on change msginfo("TextBox 1 Changed")
end textbox
define textbox t2
row 40
col 10
width 150
on change msginfo("TextBox 2 Changed")
end textbox
define button b1
row 70
col 10
caption "Click me"
action combined_show()
end button
end window
form1.center
form1.activate
return nil
function combined_show()
use master
cStr1 := master->name
cStr2 := alltrim(master->name)
form1.t1.value := strtran(cStr1,' ','-')
*- form1.t1.value := strtran(strtran(cStr1,' ','-'),'-',' ')
form1.t2.value := cStr2
close all
return nil
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 10:24 am
by esgici
rathinagiri wrote:
How many times you have clicked the button?
Sorry, I have clicked more than one time, but after changed textbox content manually.
So, I confirm the problem
I also confirm Czarny, problem goes away for not-trimmed value
Regards
--
Esgici
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 10:35 am
by gfilatov
Czarny_Pijar wrote:After some researches I see it's a "space-sign" related behaviour.
As you can see, I tried to work around it, but without success.
Please try the following simple workaround:
Code: Select all
# include "hmg.ch"
function main
private cStr := ""
private cStr1 := ""
use master
cStr := master->name
cStr1 := alltrim(master->name)
close all
define window Form1 at 0,0 width 300 height 200 main
define textbox t1
row 10
col 10
width 100
on change msginfo("TextBox 1 Changed")
end textbox
define textbox t2
row 40
col 10
width 100
on change msginfo("TextBox 2 Changed")
end textbox
define button b1
row 70
col 10
caption "Click me"
action (form1.t1.value := "",form1.t2.value := "", ;
form1.t1.value := trim(cStr),form1.t2.value := cStr1)
end button
end window
form1.center
form1.activate
return nil
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 11:40 am
by Czarny_Pijar
gfilatov wrote:
Please try the following simple workaround:
Code: Select all
...
action (form1.t1.value := "",form1.t2.value := "", ;
form1.t1.value := trim(cStr),form1.t2.value := cStr1)
...
Very clever, indeed
As long as our master did not improve the code, I suggest an even higher level of tricks :
Code: Select all
...
action (form1.t1.value := "%^$&#*@(!)",form1.t2.value := "%^$&#*@(!)", ;
form1.t1.value := trim(cStr),form1.t2.value := cStr1)
...
since the empty records in the database happen very often.

Besides, the intention was different, not firing the code at all if the text is the same.
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 11:50 am
by esgici
Czarny_Pijar wrote:
Very clever, indeed
IMO NO
Only palliative
Regards
--
Esgici
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 12:26 pm
by PeteWG
rathinagiri wrote:Please consider this sample
Code: Select all
# include "hmg.ch"
function main
private cStr := ""
private cStr1 := ""
use master
cStr := master->name
cStr1 := alltrim(master->name)
close all
define window Form1 at 0,0 width 300 height 200 main
define textbox t1
row 10
col 10
width 100
on change msginfo("TextBox 1 Changed")
end textbox
define textbox t2
row 40
col 10
width 100
on change msginfo("TextBox 2 Changed")
end textbox
define button b1
row 70
col 10
caption "Click me"
action (form1.t1.value := cStr,form1.t2.value := cStr1)
end button
end window
form1.center
form1.activate
return nil
Whenever we click the button, first textbox on change event is fired. Second textbox on change event is fired only once.
This happens only for the character type field values.
The above code "works" in MiniGUI extended.
BUT...
I think HMG official works better! (in the meaning that it works more clever)..
Let me explain..
The first time you click the button, the values of both textboxes do change and so both OnChange events get fired up.
t1 gets the value of cStr and t2 gets the value of cStr1. These two values are not the same, given that cStr1 is trimmed.
If you check the lengths of cStr and cStr1 you'll see that they are 10 and 9 respectively, but if you check the values of t1,t2 after the first click, you (surprisingly) will see that they are both 9! What is really happening is that textboxes get auto-trimmed. I don't know if this is good or not (i think it is NOT!) but this auto-trimming explains why after the second button click, t1's OnChange been fired again and t2's not.
It is because t1 been assigned a different (lengthier) value while t2 accept the exactly same value so no need to fire the OnChange event..
Bottom line. HMG seems to be clever enough to not trigger the Onchange event for the second textbox since its value does not actually change.
What remains to be explained (perhaps by Roberto) is why the textboxes are automatically trimmed and whether such a behavior is by design or is a windows inherited "feature".
---
Pete
Re: Weird behaviour of Textbox on change event
Posted: Wed Apr 07, 2010 1:38 pm
by Rathinagiri
Fantastic research Pete.
Great.
Thanks friends for extensive testing.
I don't know if this is good or not (i think it is NOT!)
I too second Pete.