Главная страница | назад





Article #16798: Porting strings from 16 to 32-bit

 Question and Answer Database
FAQ1798D.txt Porting strings from 16 to 32-bit
Category :Object Pascal
Platform :All
Product :All 32 bit
Question:
When I port my code from 16 to 32 bit, record types that contain
strings do not function correctly. What has happened?
Answer:
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;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99