Recent

Author Topic: Cirillic message with TDomNode.ChidNodes.NodeName  (Read 4309 times)

gvido

  • Newbie
  • Posts: 2
Cirillic message with TDomNode.ChidNodes.NodeName
« on: February 21, 2012, 07:09:20 am »
how to fix the output in such a situation?

showmessage('Атрибут '+tempxml.ChildNodes.Item[1].NodeName);

is show this - ???????? record  - it is wrong.

But if i showmessage('Атрибут ');

is show this  - Атрибут it is good.

my xml file:
<?xml version="1.0" ?>
<config>
   <record   id="0" file="dsc00771.jpg" timer="3000"  />
</config>

my os Windows 7 x64 rus

lazarus 0.9.30.2
FPC 2.4.4
x86_64-win32/win64

Zoran

  • Hero Member
  • *****
  • Posts: 1990
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Cirillic message with TDomNode.ChidNodes.NodeName
« Reply #1 on: February 21, 2012, 09:32:38 am »
I can confirm this. This is really strange, but the workaround seems to be involving an auxiliary string variable:
Code: [Select]
var
  S: String;
...

  S := 'Атрибут ';
  S := S + tempxml.ChildNodes.Item[1].NodeName;
  ShowMessage(S);

However, if you put in one line
Code: [Select]
S :=  'Атрибут ' + tempxml.ChildNodes.Item[1].NodeName;, it does not work! Strange.
« Last Edit: February 21, 2012, 09:37:00 am by Zoran »
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Zoran

  • Hero Member
  • *****
  • Posts: 1990
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Cirillic message with TDomNode.ChidNodes.NodeName
« Reply #2 on: February 21, 2012, 02:53:58 pm »
After looking into source code, I see that NodeName is WideString (Actually, DOMString, which is mapped to WideString). The problem lies in mixing WideString and UTF8 encoded String. LCL components always expect UTF8, so you should always convert WideString to UTF8 (use UTF8Encode function):
Code: [Select]
showmessage('Атрибут '+ UTF8Encode(tempxml.ChildNodes.Item[1].NodeName));
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

gvido

  • Newbie
  • Posts: 2
Re: Cirillic message with TDomNode.ChidNodes.NodeName
« Reply #3 on: February 21, 2012, 10:55:17 pm »
I can confirm this. This is really strange, but the workaround seems to be involving an auxiliary string variable:
Code: [Select]
var
  S: String;
...

  S := 'Атрибут ';
  S := S + tempxml.ChildNodes.Item[1].NodeName;
  ShowMessage(S);

This code is not working properly. :(

 
Code: [Select]
S :=  'Атрибут ' + tempxml.ChildNodes.Item[1].NodeName;, it does not work! Strange.
After looking into source code, I see that NodeName is WideString (Actually, DOMString, which is mapped to WideString). The problem lies in mixing WideString and UTF8 encoded String. LCL components always expect UTF8, so you should always convert WideString to UTF8 (use UTF8Encode function):
Code: [Select]
showmessage('Атрибут '+ UTF8Encode(tempxml.ChildNodes.Item[1].NodeName));

This code works gives the correct result. A custom message can be read. Thank you. :D

 

TinyPortal © 2005-2018