unisynedit 在Delphi 2010下的编译问题

官方下载到uniSynedit的压缩包后,只有for2009的版本,用2010打开,也是没有问题的。编译的时候,在SynEditHighlighter.pas报错:

function TSynCustomHighlighter.IsWordBreakChar(AChar: WideChar): Boolean;
begin
  case AChar of
    #0..#32, '.', ',', ';', ':', '"', '''', '?, '`', '?, '^', '!', '?', '&',
    '$', '@', '?, '%', '#', '~', '[', ']', '(', ')', '{', '}', '<', '>',
    '-', '=', '+', '*', '/', '\', '|':
      Result := True;
    else
      Result := False;
  end;
end;

就是多出了好几个的?,而无法编译通过。

其实,就是因为这些里面有些utf8字符,而Delphi默认的用cp936的文件格式打开,导致的错误。正确的应该是

function TSynCustomHighlighter.IsWordBreakChar(AChar: WideChar): Boolean;
begin
  case AChar of
    #0..#32, '.', ',', ';', ':', '"', '''', '´', '`', '°', '^', '!', '?', '&',
    '$', '@', '§', '%', '#', '~', '[', ']', '(', ')', '{', '}', '<', '>',
    '-', '=', '+', '*', '/', '\', '|':
      Result := True;
    else
      Result := False;
  end;
end;

用正确的代码粘贴修改后,保存,Delphi2010会提示包含utf8字符,是否保存为utf8,选择“是”即可。

同样的,有几个文件,如synedit.pas,syneditsearch.pas也有相同的一段,做同样的修改。

另外:synhighlighterjava有一段

function TSynJavaSyn.IsIdentChar(AChar: WideChar): Boolean;

begin

case AChar of

    '_', '$', '0' .. '9', 'a' .. 'z', 'À' .. 'Ö', 'Ø' .. 'ö', 'ø' .. 'ÿ':

    ‘_’, ‘$’, ‘0′..’9′, ‘a’..’z', ‘A’..’Z', ‘?..’?, ‘?..’?, ‘?..’ rsquo;:

      Result := True;

    else

      Result := False;

end;

end;

红色为错误的。

synhighlighterxml有:

function TSynXMLSyn.IsNameChar: Boolean;

begin

case fLine[Run] of

    ‘0′..’9′, ‘a’..’z', ‘A’..’Z', ‘_’, ‘.’, ‘:’, ‘-’:

      Result := True;

    else if fLine[Run] > ‘À’ then // TODO: this here is very vague, see above

    else if fLine[Run] > ‘? then // TODO: this here is very vague, see above

      Result := True

    else

      Result := False;

 

end;

end;

把编译错误和warning处理完后,编译就很顺利了。

附上修改后的安装包文件:

但是发现一个难以忍受的问题:
   一般在文本里写字,用回车就能换行,并且光标跳到下一行的首位;
   可是该版本的synEdit回车虽然能换行,但是光标不动,使用起来非常别扭。


修改方法1
procedure ExecuteCommand(Command: TSynEditorCommand; AChar: WideChar;
       Data: pointer); virtual;
这个函数的换行处理,也就是ecLineBreak;里面有代码
if Command = ecLineBreak then
begin
//if SpaceCount2 > 0 then 这句注释掉
begin
    SpaceBuffer := Copy(Lines[BackCounter], 1, SpaceCount2);
    InternalCaretXY := BufferCoord(1, CaretY +1);
    for i := 1 to Length(SpaceBuffer) do
      if SpaceBuffer[i] = #9 then
        CommandProcessor(ecTab, #0, nil)
      else
        CommandProcessor(ecChar, SpaceBuffer[i], nil);
end;
end;
可见,其实这个东西是可以换行的,只是有个条件,就是字符串信息的左边需要有空格,如果是顶头写了文字,换行就不会执行了,所以
把里面的if SpaceCount2 > 0 then 这句注释掉就可以了

修改方法2

我是在7442行加了个
   else
     InternalCaretXY := BufferCoord(1, CaretY +1);

修改方法3


procedure TCustomSynEdit.ExecuteCommand(Command: TSynEditorCommand; AChar: WideChar;
这个过程里修改;

就一句话;
大概在7396行,
有一句判断
           if Len >= CaretX then
我把它去掉了,修改成:
           if   1=1   then    
就可以了;

不知道有没有副作用,反正现在可以了。

原文地址:https://www.cnblogs.com/MaxWoods/p/2415666.html