Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 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;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use