[fpc-devel] new string - question on usage

Michael Schnell mschnell at lumino.de
Wed Oct 12 10:03:13 CEST 2011


On 10/11/2011 10:11 PM, Hans-Peter Diettrich wrote:
>
>> (a) Sorry, but this does not answer the question I tried to ask 
>> (Difference between a possible type called RawByteString and a basic 
>> "new string" variable that happens to be set to the Encoding ID 
>> "RawByte").
>
> When I have a variable of type AnsiString, and assign an string to it, 
> then its encoding is reported as 1252 (my system codepage). On Paul's 
> machine it will have a different encoding, I assume?
>
Via personal consulting ( :) ) I learned that the multiple new Pascal - 
string - types just are a kind of syntax-candy for an underlying common 
dynamically typed (and functioning in that way) string type. Seemingly 
when allocated theses strings get an appropriate encoding ID that is 
effective even with a zero length.

Seemingly (other than I assumed) a " := " between new strings does not 
preserve the encoding, but performs an encoding conversion to the 
target's encoding ID.

So for preventing a conversion, you need to make sure that the target 
has the same (or a compatible) encoding ID as the source. (Either by 
using the appropriate string types (hoping the the encoding ID has not 
been changed ) or by using SetCodePage.) I suppose there also is a 
function that is done to do a "pure" code-ID preserving assignment.

I suppose a variable of the type "String" is pre-loaded with the 
predefined "System" encoding ID.

-Michael



More information about the fpc-devel mailing list