| |
| Read and BlockRead file function failure in 32bit. |
 |
When I port my code from 6 bit Delphi to 32 bit Delphi, the read and BlockRead function no longer seem to work correctly. Is this a bug?
No. In 32 bit environments, records are automatically aligned on 32 bit boundaries when the $A+ compiler directive is in effect. This is done by padding the record so each record will be located on a 32 bit boundary. If you are reading in data from a file containing non-aligned records, the data may not be read in correctly if you are using automatic record alignment. To turn off automatic record alignment for a given record type, use the "packed" record attribute. Globally turning off record alignment with the $A- is not recommended, as much of the system requires record alignment to be on. The following example demonstrates the size difference of a packed and unpacked record.
Example:
type TSomeRec = record
w : word;
b : byte;
w2 : word;
end;
type TSomePackedRec = packed record
w : word;
b : byte;
w2 : word;
end;
procedure TForm .Button Click(Sender: TObject);
var
r : TSomeRec;
s : TSomePackedRec;
begin
ShowMessage(IntToStr(SizeOf(r))); {displays 6}
ShowMessage(IntToStr(SizeOf(s))); {displays 5};
end;
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|