Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.glorb.com!feeder.erje.net!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Hans-Peter Diettrich Newsgroups: comp.lang.pascal.delphi.misc Subject: RawByteString and SetCodePage buggy? Date: Sun, 18 Sep 2011 15:28:16 +0200 Lines: 30 Message-ID: <9dm6feFvk3U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net GHfGzZv16Dx3ODDiRnDRNAcvdXnT2k87MNDcW+1VRcScE/lFOq Cancel-Lock: sha1:Yf0TqC7H+3EIhJPuWMfE+jMcMys= User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) Xref: x330-a1.tempe.blueboxinc.net comp.lang.pascal.delphi.misc:75 I just noticed very strange behaviour of RawByteString and SetCodepage, in Delphi XE: var //used as arguments for test() a: AnsiString; //initialized to 'abcäöüß012' u: UnicodeString; //initialized to a procedure test(r: RawByteString; cp: word); begin WriteLn('in: ', StringElementSize(r), ' cp: ', StringCodePage(r), ' len=', length(r)); WriteLn('"', r, '"'); //writes garbage for non-OEM chars, of course SetCodePage(r, cp, true); WriteLn('out: ', StringElementSize(r), ' cp: ', StringCodePage(r), ' len=', length(r)); a := r; //use the result, so that nothing can be optimized away WriteLn('"', r, '"'); end; This reveals the following behaviour: 1) UnicodeString is converted to AnsiString, before passed to test. 2) Setting codepage to 1200 doesn't change anything??? 3) Conversion to UTF-8 seems to work (length changed). 4) Conversion from UTF-8 to Ansi results in an empty string??? At least #4 looks like a bug? What about #2? DoDi