Thanks for all your suggestions.
The answer as correctly pointed out was related to record alignment. In the D5 compiler option I had the Align Record Fields Selected but D2006 gives align options 0-8 setting this option. Setting this option to 8 addresses the alignment problem. -----Original Message----- From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf Of wvido...@metsec.com Sent: 23 August 2010 08:41 To: delphi@elists.org Subject: RE: Error reading Binary files using Delphi2006 Yes, the record is not defined as PACKED but in the compiler option for D5 the Align Record Fields option is checked. In D2006 there in now the Records Field Alignment with drop down options 0-8, Is this the key difference? voestalpine - One step ahead -----Original Message----- From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf Of Richard Saunders Sent: 21 August 2010 13:58 To: delphi@elists.org Subject: Re: Error reading Binary files using Delphi2006 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 This email is intended for the addressee only. Please see our email policy at http://www.metsec.com/asp/home/edisclaimer.asp _______________________________________________ Delphi mailing list Delphi@elists.org http://lists.elists.org/cgi-bin/mailman/listinfo/delphi This email is intended for the addressee only. Please see our email policy at http://www.metsec.com/asp/home/edisclaimer.asp _______________________________________________ Delphi mailing list Delphi@elists.org http://lists.elists.org/cgi-bin/mailman/listinfo/delphi