On 8/20/2010 11:32 AM, wvido...@metsec.com wrote:
I wrote an application using delphi5 which reads and writes binary file using TFilestream. But then when I ported the application to Delphi 2006 the files written using old application returns junk data in the new version.
The record that is being streamed to/from the file must have a different structure between the Delphi versions. While the source code definition of the record can be identical, internal differences between the Delphi versions can cause the internal structure to be different. I'll bet the definition does not specify a PACKED RECORD. If it did the internal structure would likely be identical since PACKED indicates you want the field alignment to be as compact as possible and that result probably did not change between Delphi versions.
How to fix it? Well, you probably will need to detect files written by the D5 program vs. the D2006 program. If the record is the only thing written to the file then the byte length of the files should differ. You could use the byte length to tell you which version of the program wrote the file.
If you look at the file using a hex editor you should be able to detect where the record structures differ. You can then adjust the record definition of the current program to be able to read the older files.
Finally, I would change the definition to be PACKED RECORD from now on. That would avoid this problem going forward.
-- Rich S. _______________________________________________ Delphi mailing list Delphi@elists.org http://lists.elists.org/cgi-bin/mailman/listinfo/delphi