Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Porting strings from 16 to 32-bit


When I port my code from 6 to 32 bit, record types that contain strings do not function correctly. What has happened?   

    Traditionally, strings that are defined with no length parameter would default to having a length of 255 characters. With the advent of 32 bit Delphi, strings with no defined length default to a long string. Long strings are pointers to a reference counted AnsiString. Long string types are not recommended for use in structures that are intended to be written or read from a disk file. To port your code correctly, you need to explicitly set the expected length of the string in the record, otherwise, a long string is used in place of the original string in the record, leading to unexpected results. Example:

      ShortStringRec : record
        s : string[255]; {this uses a short string - ok}
      end;
      LongStringRec : record
        s : string; {this uses a long string - not ok}
      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