save trigger

Started by Marc van Cauwenberghe, May 17, 2012, 07:39:24 AM

Previous topic - Next topic

Marc van Cauwenberghe

Hi,

I would like to know how anyone programs the saving of records once the dataentry is done or some editing have been done in the dataentry form.
My aim is to not have to save a record if nothing has changed.
I have used several methods in the past years. Setting a so called 'IsDirty' flag if one edited a field, comparing fields, ...
I now use the following:
When I retrieve a record form possible editing, I put record in a type, e.g. UserType and then use that to fill the fields.
When  someone clicked save I put the fields in an other type e.g. UserFormType.
I then compare the 2 Types.

Any comments, suggestions?

Thanks,
Marc


Rolf Brandt

I usually check change event of controls. Whenever a change occurred I enable the save button, otherwise it stays disabled.

But your way of comparison sounds very good to me.


Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Marc van Cauwenberghe

Thank you Rolf,

So your checking for the EN_CHANGE event. Am I correct in thinking that if one makes a change and then undoes his edit this would be still have triggered the EN_CHANGE so setting the what I like to call the 'IsDirty' flag. I could off course combine the 2 and just do a type compare if a EN_CHANGE event was triggered in one of the fields.

Thanks and have a nice day.
Marc

Paul Squires

#3
One word of caution, if you are depending on EN_CHANGE you should realize that message will fire when your Form is first created. This is because FF will assign text to the edit control after it is initially created in WM_CREATE. We have discussed this in this forum in the past and the technique to use is to set a global flag that is tested in EN_CHANGE and, if FALSE, do not process the EN_CHANGE notification. You set this global variable to TRUE at the end of your WM_CREATE message handler for your Form so subsequent EN_CHANGE notifications will be caught.

Let me look for a past post on this.....

(Edit)
Check out this post:  http://www.planetsquires.com/protect/forum/index.php?topic=2502.msg19167#msg19167
Paul Squires
PlanetSquires Software

Nathan Durland

I do something similar.  There's a global gFormIsDirty that I set %True in EN_CHANGE.  The last line in FORM_CREATE is gFormIsDirty = %False.  It is also set %False after a save, at form unload, etc.

Marc van Cauwenberghe