Weird behaviour of Textbox on change event

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Weird behaviour of Textbox on change event

Post 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.
Attachments
main1.zip
(677 Bytes) Downloaded 337 times
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Weird behaviour of Textbox on change event

Post by esgici »

Hi Rathi

I couldn't see the problem, in my machine everything is right :(

( XP SP-2 )

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Weird behaviour of Textbox on change event

Post 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.
Attachments
main1exe.zip
(720.31 KiB) Downloaded 383 times
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: Weird behaviour of Textbox on change event

Post 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
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Weird behaviour of Textbox on change event

Post 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 :(

Code: Select all

cStr1 := SUBS(master->name,5)
Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Weird behaviour of Textbox on change event

Post 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: :idea:

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
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: Weird behaviour of Textbox on change event

Post by Czarny_Pijar »

gfilatov wrote: Please try the following simple workaround: :idea:

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.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Weird behaviour of Textbox on change event

Post by esgici »

Czarny_Pijar wrote: Very clever, indeed :)
IMO NO :!:

Only palliative :(

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Weird behaviour of Textbox on change event

Post 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
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Weird behaviour of Textbox on change event

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply