Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29429 Discusiones

Recognising changes in Data Structures

acar
Principiante
1.275 Vistas
Hi, the application that I'm developing is an engineering application. Users open an existing model database file, do some work, and then save the file. I need a feature to check whether or not the user has actually changed the data in a model so that he/she can be prompted appropriately to save before closing/quiting the application. I have created a rudimentary way of doing this by writing out the structure to file before and after editing and then comparing checksums. This method is not particularly elegant and the checksum routine I obtained is a stand alone executable that I need to run via the SYSTEM command (and thus temporarily throws up a console window over my application). I also have a suspicion that the method is not bomb-proof.
I wonder therefore if anyone has any suggestions or recommendations on how one might implement this?
Thanks,
Angus.
0 kudos
8 Respuestas
Arjen_Markus
Colaborador Distinguido II
1.275 Vistas
You could keep track of changes (at least in a rough way) by setting a flag each time the user
presses an OK button or whatever is relevant in your application. Irealise that this is
not always possible or reliable and then saving the data in a file is indeed a much easier
way.
To compare the contents of two files, you could use an MPD5 checksum orSHA1 or any of
these cryptographic keys. You ought to be able to find plenty of implementations on the Internet
for them. It would then be a matter of creating an interface to the routine(s) and then you'd
be independent of an external program

Regards,

Arjen
IanH
Colaborador Distinguido III
1.275 Vistas
In a GUI application this would often be handled by having every event handling procedure that could modify the data set a document-global file-has-been-changed flag. This same flag is cleared when the document is saved, or if the entire undo stack since the last save gets popped.

(In your case, every "user entry point" style procedure in the "do some work" part of your description would need to set this flag.)

anthonyrichards
Nuevo Colaborador III
1.275 Vistas
Let's hope that you hold a protected master copy of the data file that user's cannot screw up and replace with the screwed-up version?
acar
Principiante
1.275 Vistas
Thanks arjenmarkus, the software already knows where a data structure might change so I just need a checking routine. I'll take another look for an implementation of the checksum routines you suggest.
acar
Principiante
1.275 Vistas
Thanks IanH, yes I already know when the data might change using my own flag model_database_changed. I just need a quick and reliable method for making the check as to whether or not the data in a structure has changed.
acar
Principiante
1.275 Vistas
Good point - hopefully my software will protect the user against this .... but that is yet to be tried in practise! I have not yet coded an undo/redo facility into the software but that is probably something I need to consider for the future.
Paul_Curtis
Colaborador Valioso I
1.275 Vistas
All edit dialogs should operate on a copy of the original data structure. If the user ends the edit with "ok/accept", the edited copy then replaces the original and sets the "changed" flag; if the user cancels the dialog, the edited material simply vaporises and the original is left intact.
acar
Principiante
1.275 Vistas
Thanks Paul. It took me some time to recognise that this is what I should be doing but I do now operate in this way.
Responder