fastreport中的对汉字的支持

fastreport4.79的脚本编辑器:frxSyntaxMemo,fs_Syntaxmemo

第一个是用在TFrxAdoquery的sql编辑器中的,第二个是个独立的控件,用来支持几个常用脚本的语法加亮

存在的问题是:可以删除半个汉字,可以将光标移动至汉字中间

我现在的项目中,多处sql语句中用到汉字(select col1 as 第一列....),所以自己动手改了一下fastreport源码

原理是使用bytetype函数,判断光标位置的字符是否是汉字,bytetype的帮助如下:

Indicates whether a byte in a string is a single byte character, the first byte of a double byte character, or the second byte of a double byte character.

返回值:type TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);

                                              单字节                汉字首             汉字尾


处理源码中的几处事件就可以使这个编辑器支持汉字了

例如:

  1 procedure TfsSyntaxMemo.DoLeft;

 2 var
 3   s: string;
 4 begin
 5   Dec(FPos.X);
 6   s := LineAt(FPos.Y - 1);
 7   if bytetype(s, FPos.X) = mbTrailByte then
 8   begin
 9     dec(Fpos.X);
10   end;
11   if FPos.X < 1 then
12     FPos.X := 1;
13   SetPos(FPos.X, FPos.Y);

14 end;

fr4.79_cn_path.rar

posted @ 2008-11-16 20:39  _Zerg  阅读(1138)  评论(0编辑  收藏  举报