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?
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.