A checksum is a computed value that is representative of the data on which the computation is based. It is not possible to recover the original data from the checksum value. In Delphi applications, checksums can be used in a variety of ways. To mention just two
- Use a 32 bit checksum at the start of data files streamed out to disk. When the user attempts to open the file, recompute the checksum for the data starting at byte offset 4 and compare it with the stored value. This way you can deal with corrupted files before you attempt to read them. This is far better than attempting to read the file anyway and then dealing with all the exceptional conditions that are liable to arise if it turns out to be corrupted.
- In most applications there will typically be many ways in which a user can modify the underlying data. When this happens the user must be prompted to save the data before exiting the application. A naive approach is to set a
Changed
flag each time the user edits text, checks/unchecks a checkbox etc. The problem is that the user could just as easily undo the change by reversing the operation. However, theChanged
flag would remain set and you would end up needlessly warning the user about the need to save his/her work. A better approach is to calculate an initial checksum for the data and only prompt for a save if it is observed to have changed.
We offer Delphi implementations for three checksum algorithms