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

Recognising changes in Data Structures

acar
초급자
1,199 조회수
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 포인트
8 응답
Arjen_Markus
명예로운 기여자 II
1,199 조회수
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
0 포인트
IanH
명예로운 기여자 III
1,199 조회수
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.)

0 포인트
anthonyrichards
새로운 기여자 III
1,199 조회수
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?
0 포인트
acar
초급자
1,199 조회수
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.
0 포인트
acar
초급자
1,199 조회수
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.
0 포인트
acar
초급자
1,199 조회수
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.
0 포인트
Paul_Curtis
소중한 기여자 I
1,199 조회수
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.
0 포인트
acar
초급자
1,199 조회수
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.
0 포인트
응답