[fpc-devel] new string - question on usage

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Oct 12 12:37:29 CEST 2011


Sven Barth schrieb:
> Am 11.10.2011 23:09, schrieb Hans-Peter Diettrich:

>>> In short, see it as if text now has a mandatory encoding attached. If 
>>> the
>>> runtime doesn't know the type, then it is not text, but binary, and you
>>> should treat it as such.
>>
>> Can you give an example, how the runtime can not know the type of an
>> string?
> 
> If you just opened a file (no reading done yet) you don't know the 
> encoding.

Right, but it's still a file, not a string.

> Or if the file has no BOM then you might want to guess the 
> encoding based on the content read. As long as you haven't guessed the 
> encoding (no matter whether the guess is right or wrong) you don't know 
> the encoding.

Right2. When no encoding is specified, Delphi reads (part of) the file 
into a byte array and looks for a BOM (TEncoding.GetBufferEncoding). If 
none is found, the preferred encoding (of the TStrings/TStream instance) 
is used, or system encoding as the last resort.

DoDi




More information about the fpc-devel mailing list