How can I sense when a field is changed by the user during editing but not by program code?
Right now, when code changes the field the textchange event code enables the save button,
I just want it to enable the button with the user updates the field.
I know I can use the keydown event but that does not sense if the user pastes data into the field.
Do I have to make a global that signals when code is updating fields and ignore textchange events until it is done?
If there are a hundred fields does that mean 100 textchange events fire that I have to ignore?
If code clears the ignore flag won’t the last few textchange events still fire and enable the button anyway?
Is there a better way?
All standard controls will fire events when changed by code or by the user - thats by design.
However this is where subclassing them comes in handy as you can create a version that you can, in your code, set a flag that tells your custom subclass to ignore the events that are about to be sent because you are making changes in code.
Try this (this is a VERY simple illustration of whats possible with subclasses)
Create a new Class in your project - this is Class1
Set the Super to be “TextField”
Add a protected property “changingByCode as boolean”
Implement the textchange event in your new class event as
if changingbyCode then return
raiseEvent TextChange
Add a new Event definition “TextChange”
Add a method “SetByCode( s as string )” and put this code in it
changingByCode = true
me.Text = s
changingByCode = false
Now put an instance of your new control on a window - it will be called Class11 if you don’t change the name
Implement its text change event with
msgbox "textchange"
Then add a pushbutton to the window & put this code in its Action event
Class11.SetByCode( "hello" )
Run
When you type you should get the msgbox
When you press the button you wont
This is a VERY simple illustration of whats possible (and there are lots of other ways to generalize this to make it apply to more controls types easily)
I am trying to implement this but getting an error. I have composed an image that shows the class, the control and the error. Do you know what I am doing wrong? Thanks.
Here is the picture: