Board index » delphi » D3 to D5 file read problem
Gary Jones
![]() Delphi Developer |
Thu, 09 Jan 2003 03:00:00 GMT
|
Gary Jones
![]() Delphi Developer |
Thu, 09 Jan 2003 03:00:00 GMT
D3 to D5 file read problemHi. I'm porting an application from Delphi 3 to Delphi 5 and hit a problem Here's a simplified example of what seems to be the root cause of the type stringz255=array[0..255] of char; TtestData=record var Files of type testDataFile have been written to disk using Delphi 3. When the files are read using Delphi 5, I get a "Read beyond end of Any ideas? -- |
Gary Jone
![]() Delphi Developer |
Thu, 09 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemIn article <397b3af7.52636...@News.Dial.Pipex.Com>, Mike <pb56DEL...@dial.pipex.com> writes Quote>Don't be offended but the naming of your variables could be better Quote>The type declaration should look something like this: (writing and reading). My problem is reading the data structure in Delphi 5. The use of null terminated strings is deliberate. Quote>The routine below is just a demo for reading the file while not eof loop which isn't relevant since there's only one record per file). -- |
Gary Jone
![]() Delphi Developer |
Thu, 09 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemIn article <Jf0aoCA3owe5E...@bohr.demon.co.uk>, Gary Jones <newsmas...@bohr.demon.co.uk> writes Quote
string25=string[25]; Equivalently, the illustrative data structure should have read: TtestData=record Sorry about that. Anyway, still hoping for some clues as to what's going on. -- |
Dr John Stockto
![]() Delphi Developer |
Thu, 09 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemJRS: In article <Jf0aoCA3owe5E...@bohr.demon.co.uk> of Sun, 23 Jul 2000 16:07:35 seen in news:alt.comp.lang.borland-delphi, Gary Jones Quote<newsmas...@bohr.demon.co.uk> wrote: "packed record" in the manual, maybe. The solution is probably to make the record packed in D5, and to pad it The right way to do it is to use packed records in both D3 & D5. It is possible that one or more of your types have changed actual size -- |
Martin Prikry
![]() Delphi Developer |
Fri, 10 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemQuote> I'm porting an application from Delphi 3 to Delphi 5 and hit a problem in Delphi3 and Delphi5, eg: sizeof(TTestData.myDate) If they don't equal, problem is in different type declaration of types in If they equals, problem is probably in word alignment, see Sorry for my bad English. -- |
Gary Jone
![]() Delphi Developer |
Fri, 10 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemThanks to John and Martin. The problem is definitely due to this packed record business. I ran a test on my test data structure: type TtestData=record and also a packed version of the same: TpackedTestData=packed record I compiled and ran tests in D3 and D5 and here are the results: {best viewed in a non-proportional font} DELPHI 3 DELPHI 3 myDate 8 0 8 0 whole record 292 290 DELPHI 5 DELPHI 5 myDate 8 0 8 0 whole record 296 290 So D5 is trying to read 296 bytes, but the record is only 292 bytes So what to do? The option of using packed record in D5 and inserting padding bytes I used code such as the following... With the clues you've given I could refine my search in deja.com and I Bearing in mind that in the real application the record contains Thanks for the help so far. -- |
Cezar Lenc
![]() Delphi Developer |
Fri, 10 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemI had the same problem upgrading from Delphi 4 to Delphi 5. I was using sizeof() to read records from a BLOB field. In both Delphi 4 and Delphi 5, the sum of the sizeof() of all elements of the record were 34. The sizeof() of the record was 36 and using Delphi 5, sizeof() of the same record was 40. So, the actual size of the record insn't the sum of the sizeof() of all its elements (unless it is a packed record) because the elements of the record are aligned on word or double-word. And it seems that the aligning of the values in the record changed from Delphi 4 to Delphi 5, but this is just a guess. The solution may be using a TFileStream to read the file, so you can read any amount of data using the TFileStream.Read method. Martin Prikryl <martin.prik...@seznam.cz> escreveu nas notcias de Quote> > I'm porting an application from Delphi 3 to Delphi 5 and hit a problem |
Dr John Stockto
![]() Delphi Developer |
Sat, 11 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemJRS: In article <HXZZ6BAEmIf5E...@bohr.demon.co.uk> of Mon, 24 Jul 2000 19:23:00 seen in news:alt.comp.lang.borland-delphi, Gary Jones Quote<newsmas...@bohr.demon.co.uk> wrote: including the last. Construct a test program, console mode, DCC32 -cc : Run this in D3 with your exact D3 type definition. Repeat for C, D, ...; then pad the end to get SizeOf right. You will need the same amount of padding after each occurrence of any It may be safest to use one program for D3, D5, using -- |
Gary Jone
![]() Delphi Developer |
Mon, 13 Jan 2003 03:00:00 GMT
Re:D3 to D5 file read problemThanks for the help. It seem that the easiest solution might be to write a utility in D3 to But... unpacked records are the default and are structured to make CPU -- |
1. DES component for D5 or Translating DCU D3 files to D5
3. Deploying D5's BDE with D3 App and D3's ISE
4. Conversion problems D3 to D5
5. Conversion Problems from D3 to D5
6. Upgrade problems from D3 to D5?
7. Not the usual D3-D5 type library problem