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