[fpc-devel] new strings, rawbyte type, but what about "raw" encoding

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue Oct 11 09:44:28 CEST 2011


Martin schrieb:
> On 11/10/2011 02:46, Marco van de Voort wrote:
>> In our previous episode, Martin said:
>>> Now my question.
>>> Is there (or going to be) an encoding, that is "unknown" and will never
>>> be converted. but can be assigned to any of the types?
>> Afaik, there is no such thing in Delphi.
>>
> 
> Slight change in topic:
> 
> What encoding does a pchar have? Or rather what does it get, when for 
> example assigned to a rawbytestring?

Good question. Delphi claims that AnsiChar corresponds to the first 256 
Unicode characters, but this may not always hold :-(


> what happens (or is intended to happen), if I cast a string to pchar, 
> before handing it over as param?
> 
> procedure foo(a: Utf8String);
> .....
> 
> var s: string;
> foo(pchar(s));

This will work only when "string" is UTF-16, since PChar is a pointer to 
Unicode. You can try figure out what copies and conversions the compiler 
may insert, in order to match the given casts and argument types.

> or
> foo(pchar(@s[2]));

In all cases a temporary UTF8string will be used, matching the strong 
argument type of foo.

See also: ms-help://embarcadero.rs_xe/vcl/System.PAnsiChar.html

DoDi




More information about the fpc-devel mailing list