Let’s say we have a Win32 form with a Save toolbar button and some sontrols like a CheckBox are on the form, now we write a one line code for onchange event of checkbox to enable/disable the Save button. Let’s say checkbox is selected at first, Save button disabled, now de-select the checkbox, Save button becomes enabled…now select the checkbox again Save button is still enabled…Same for a TextBox for example. Let’s say its text is “Hi”…change it to “Hi Bye” , Save is enabled…change it BACK to “Hi” as it was, Save remains enabled…
Is there a model we can use to prevent these wrong enabling/disabling of save button?
Let’s say we have a Win32 form with a Save toolbar button and some
Share
You could store the last saved state, and compare the current state to it whenever it changes, to see if they’re identical. If so, disable the button.
If these comparisons are expensive, you could make this more efficient, by calculating a hash value over all of the fields that need to be saved, and only doing the proper comparison if the hash of the last saved state matches the hash of the current state.