Quite often, when I make VCL programs, I come across this scenario:
- I have several components on the form that users are allowed to mess with. Most often this is a bunch of edit fields.
- The contents of these edit fields should be checked by the OnChange event when the user manually enters data.
- Somewhere else on the form, there is some component that the user can click to get the default values ββloaded into the edit fields (in TEdit :: Text).
Now I want that whenever a user types in TEdit :: Text, the OnChange event should handle the user's input. But when my program sets TEdit :: Text to the default value, this is not necessary, because then I know that this value is correct.
Unfortunately, writing type code myedit->Text = "Default";raises the OnChange event.
I usually solve this by believing that this is a rather ugly approach: by creating a bool variable is_user_inputthat checks TEdit::OnChange. If so, TEdit :: Text will receive confirmation, otherwise it will be ignored. But, of course, this does not prevent the program from starting TEdit::OnChangewhen it is not needed.
Is there a better or cleaner way to achieve this?
OnChange , ? , OnChange . TEdit::Enabled, , OnChange .