| |
| 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;
|
|
| 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
|