Link to home
Start Free TrialLog in
Avatar of wipnav
wipnav

asked on

Record alignment, Delphi 4 vs Delphi 5

I wrote to a file in Delphi 4 using the following record structure:

TRouteFileHeader = record      // 40 in Delphi 5, 32 in Delphi 4
  HRouteId: string[8];              // 9
  HRouteVersion: string[5];     // 6
  HOperationCount: Integer;  // 4
  HLoadDate: TDateTime;       // 8
  HFileVersion: string[2];        // 3
end;

I recompiled in Delphi 5 and tried to read the same file. The first three fields were okay, but the last two were not. When I did a sizeof on the record, it was 40 bytes. In Delphi 4 it was only 32 bytes (which seems about right).

I think this may have something to do with aligning records on 32 bit boundries. I tried to change that setting, and it did make a difference. I couldn't get the Delphi 5 program to correctly read the file though.

My question is, is there a setting in Delphi 5 that will allow it to correctly read this file as written in Delphi 4?
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wipnav
wipnav

ASKER

Thanks for your help. I will try that.
Your welcome.

As a general rule experts here do not mind if you verify an answer works for you before grading.

Let me know how it goes.

Cheers,

Raymond.
Avatar of wipnav

ASKER

Raymond,

I tried it today and didn't work. I think using a packed record made things worse. I didn't get a chance to document exactly what I got, but it didn't look too good. I still wonder what they changed in Delphi 5 to cause this problem.

Regards,

Bill
I found the definitive guide in section 18-7 of the D3 Object Pascal Guide. According to that, the record should look like this (sorry for the incorrect initial answer):

TRouteFileHeader = packed record
  HRouteId: string[8];            
  HRouteVersion: string[5];  
  Dummy1 : Byte;    
  HOperationCount: Integer;  
  HLoadDate: TDateTime;        
  HFileVersion: string[2];        
  Dummy2 : Byte;
end;

I don't think there were changes between D3 and D4, though there have been for D4 to D5.

Cheers,

Raymond.
Avatar of wipnav

ASKER

Raymond,

The second answer worked. Thanks for your help. My initial grade stands.

Regards,

Bill