Maintaining Alignment of records across units.
Help!!
I am moving a large medical notes and billing system from Delphi 7 to Lazarus in Windows but the plan is to run under Linux.
It seems that I cannot maintain consistent record sizes across units in a single project Lazarus/FPC.
Before proving a code example, I will try and explain what is happening.
The 'packed' records contain fields of known length, of strings (String[21]) and integers (4 bytes) as well as some enumerated types (one byte) that have been used for years in a number of networked installations. The records are written to and read from typed files of the same record type. In Lazarus/FPC, I have used {$A1} and {$MINENUMSIZE 1} to force field alignment and enumerated types into the smallest memory to match the storage allocation by Delphi.
The Sizeof() intrinsic reports the correct (same as Delphi) record size if used in the unit where the record is declared. According the records are read and written to the data files correctly from that unit.
BUT from any other unit, the sizeof() intrinsic reports a larger value of types and records declared in the original 'Types' unit interface.
So, procedures written in a unit that USES the original 'Types' unit that declared the records, results in incorrect access the data files.
I have types declared in one 'Types' unit and file access in another unit.
I have a main unit that defines record types like this
Unit Types;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
{$H-}
{$A-} //for Delphi32 so that the structures are the same size as the DOS and windows versions
{$IFDEF FPC}
{$A1} //pack on single byte boundaries for FPC/Lazarus
{$ENDIF}
{$MINENUMSIZE 1} //So that enumerated types are same size as in Delphi
{$Z1}
Type
Transaction = Packed record
.....
end;
And another unit that implements file access with the same complier directives as listed above.
QUESTION: As this works in Delphi, am I missing a project wide setting in the Lazarus IDE to maintain minimum record size across units? I have been through all Project options but cannot find such a setting. Is there something else ? $CODEALIGN. ??
Any help greatly appreciated.
Laurie
Lazarus 1.4.2 FPC 2.6.2 Windows 7