﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-玄铁剑-文章分类-Delphi</title><link>http://www.cnitblog.com/MartinYao/category/7157.html</link><description>成功的途径：抄，创造，研究，发明...</description><language>zh-cn</language><lastBuildDate>Mon, 26 Sep 2011 12:56:30 GMT</lastBuildDate><pubDate>Mon, 26 Sep 2011 12:56:30 GMT</pubDate><ttl>60</ttl><item><title>Trichview标点符号问题</title><link>http://www.cnitblog.com/MartinYao/articles/42802.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 26 Apr 2008 15:59:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/42802.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/42802.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/42802.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/42802.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/42802.html</trackback:ping><description><![CDATA[在WinXP下用全拼输入法进行了测试，确实出现标点符号("，"等)无法正确输入显示的问题，但用智能ABC输入法、紫光拼音输入法、微软拼音输入法等测试，却发现是正常的，五笔输入法没有安装，未进行测试。经过仔细研究分析和用SPY截获RichViewEdit消息的结果，发现问题出现在全拼输入法输入中文标点符号时，系统发送给的消息与其他输入法不同，见下面：<br>【全拼输入法】<br>&lt;00005&gt; 007B02EC P WM_KEYDOWN nVirtKey:VK_PROCESSKEY cRepeat:1 ScanCode:33 fExtended:0 fAltDown:0 fRepeat:0 fUp:0<br>&lt;00006&gt; 007B02EC P WM_CHAR chCharCode:'.' (172) (lead) cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0<br>&lt;00007&gt; 007B02EC P WM_CHAR chCharCode:'' (163) (trail) cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0<br>&lt;00008&gt; 007B02EC P WM_KEYUP nVirtKey:00BC cRepeat:1 ScanCode:33 fExtended:0 fAltDown:0 fRepeat:1 fUp:1<br><br>【智能ABC输入法】<br>&lt;00017&gt; 007B02EC P WM_KEYDOWN nVirtKey:VK_PROCESSKEY cRepeat:1 ScanCode:33 fExtended:0 fAltDown:0 fRepeat:0 fUp:0<br>&lt;00018&gt; 007B02EC P WM_IME_COMPOSITION chDBCS:0000 fFlags:1FBF<br>&lt;00019&gt; 007B02EC P WM_IME_ENDCOMPOSITION<br>&lt;00020&gt; 007B02EC P WM_KEYUP nVirtKey:00BC cRepeat:1 ScanCode:33 fExtended:0 fAltDown:0 fRepeat:1 fUp:1<br><br>全拼输入法的中文汉字发送的消息与智能ABC输入法的中文汉字、中文标点发送的消息相同，但中文标点是将低字节与高字节作为两个WM_CHAR消息发送的，而RichView在对WM_CHAR消息的处理时存在一定的问题，就导致了不能正确输入显示中文标点。下面是处理WM_CHAR消息之后调用的代码(RVERVData.pas)：<br>procedure TRVEditRVData.KeyPress(var Key: Char);<br>var Text: String;<br>begin<br>&nbsp; if (GetRVStyle=nil) or (PartialSelectedItem&lt;&gt;nil) or not CanDelete then begin<br>&nbsp; &nbsp; Beep;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; {$IFNDEF RVDONOTUSEUNICODE}<br>&nbsp; if GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode then begin<br>&nbsp; &nbsp; Text := RVU_KeyToUnicode(Key); // ****<br>&nbsp; &nbsp; if Length(Text)=0 then exit;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; {$ENDIF}<br>&nbsp; &nbsp; Text := Key;<br>&nbsp; InsertTextTyping(Text);<br>end;<br>问题就出在标记为"****"的行，由于一个标点如"，"(0xACA3)被当作两个字符发送，这里的Key在第一次是0xA3，而第二次是0xAC，RVU_KeyToUnicode实际上就是调用MultiByteToWideChar进行Unicode转换的，它对0xA3、0xAC这样一个中文标点被分割成的两个字符的分别单独转换结果和实际的输入就不符了，在转换之后都成了0x0000(WideChar)，插入之后就不能正常显示的。因此，要解决这个问题，关键就在于不能把中文标点的低字节、高字节作为两个字符分别转换，而是应该加在一起一次转换，这样插入的结果才正确。为了验证上述的分析结果，我将这里的代码作了如下更改：<br>{ ================================== }<br>{ 2004-11-17 Added by LiChengbin &nbsp; &nbsp; }<br>var FirstChar: Char;<br>{ ================================== }<br>procedure TRVEditRVData.KeyPress(var Key: Char);<br>var Text: String;<br>begin<br>&nbsp; if (GetRVStyle=nil) or (PartialSelectedItem&lt;&gt;nil) or not CanDelete then begin<br>&nbsp; &nbsp; Beep;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; {$IFNDEF RVDONOTUSEUNICODE}<br>&nbsp; if GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode then begin<br>{ ================================== }<br>{ 2004-11-17 Modified by LiChengbin &nbsp;}<br>&nbsp; &nbsp; //Text := RVU_KeyToUnicode(Key);<br>&nbsp; &nbsp; if (FirstChar = #0) and IsDBCSLeadByte(Byte(Key)) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; FirstChar := Key;<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if FirstChar &lt;&gt; #0 then<br>&nbsp; &nbsp; &nbsp; Text := RVU_KeyToUnicode(FirstChar + Key)<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; Text := RVU_KeyToUnicode(Key);<br>&nbsp; &nbsp; FirstChar := #0;<br>{ ================================== }<br>&nbsp; &nbsp; if Length(Text)=0 then exit;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; {$ENDIF}<br>&nbsp; &nbsp; Text := Key;<br>&nbsp; InsertTextTyping(Text);<br>end;<br>再次进行了测试，OK! 中文标点可以正确输入并显示了。
<img src ="http://www.cnitblog.com/MartinYao/aggbug/42802.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2008-04-26 23:59 <a href="http://www.cnitblog.com/MartinYao/articles/42802.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>