Solved

Record alignment, Delphi 4 vs Delphi 5

Posted on 2000-02-14
6
591 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:wipnav
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 2520868
The answer is no, there is not setting (sorry). You need to declare your record like this if the D4 record size was 32:

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

In general, any record that you write to a file should be declared as 'packed'

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:wipnav
ID: 2520922
Thanks for your help. I will try that.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2520933
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.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:wipnav
ID: 2525231
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2525316
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.
0
 
LVL 1

Author Comment

by:wipnav
ID: 2529459
Raymond,

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

Regards,

Bill
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
Convert GUI app into console app for Win32 Env 5 109
select query - oracle 16 100
Firemonkey BASS_Init into a thread 17 30
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question