秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

如果在windows下project目录包含中文,编译出错时定位出错行会提示找不到文件的Bug。
这个问题是支持中文变量后发现的Bug,只存在windows,在linux是没问题的。

解决方法:
打开lazarus\ide\main.pp,找到function TMainIDE.DoJumpToCompilerMessage,按红色代码修改(lazarus 3.4在第9310行),修改完成后重新编译lazarus就可以。

//lbz+
function IsStringUTF8(strtmp: string): Boolean;
var
  nBytes: byte;
  chr: byte;
  bAllAscii: Boolean;
  i: Integer;
begin
  nBytes := 0;
  bAllAscii := TRUE;
  for i := 1 to length(strtmp) do
  begin
    chr := ord(strtmp[i]);
    if (chr and $80) <> 0 then
      bAllAscii := FALSE;

    if nBytes = 0 then
    begin
      if chr >= $80 then
      begin
        if chr >= $FC then
          nBytes := 6
        else if chr >= $F8 then
          nBytes := 5
        else if chr >= $F0 then
          nBytes := 4
        else if chr >= $E0 then
          nBytes := 3
        else if chr >= $C0 then
          nBytes := 2
        else
          Exit(FALSE);

        Dec(nBytes);
      end;
    end
    else
    begin
      if (chr and $C0) <> $80 then
        Exit(FALSE);

      Dec(nBytes);
    end;
  end;

  if nBytes > 0 then
    Exit(FALSE);

  if bAllAscii then
    Exit(FALSE);

  Result := TRUE;
end;
//lbz+
function TMainIDE.DoJumpToCompilerMessage(FocusEditor: boolean;
  Msg: TMessageLine): boolean;
var
  Filename, SearchedFilename: string;
  LogCaretXY: TPoint;
  TopLine: integer;
  SrcEdit: TSourceEditor;
  OpenFlags: TOpenFlags;
  AnUnitInfo: TUnitInfo;
  AnEditorInfo: TUnitEditorInfo;
begin
  Result:=false;

  if Screen.GetCurrentModalForm<>nil then
    exit;

  if Msg=nil then begin
    // first find an error with a source position
    if MessagesView.SelectFirstUrgentMessage(mluError,true) then
      Msg:=MessagesView.GetSelectedLine;
    // then find any error
    if (Msg=nil) and MessagesView.SelectFirstUrgentMessage(mluError,false) then
      Msg:=MessagesView.GetSelectedLine;
    if Msg=nil then exit;
  end else begin
    MessagesView.SelectMsgLine(Msg);
  end;
  Msg:=MessagesView.GetSelectedLine;
  if Msg=nil then exit;

  // first try the plugins
  if IDEQuickFixes.OpenMsg(Msg) then exit;

  Filename:=Msg.GetFullFilename;
  {$ifdef MSWINDOWS}//lbz+
  if not IsStringUTF8(Filename) then
    Filename:=cp936toutf8(Msg.GetFullFilename);
  {$endif}//lbz+
  LogCaretXY.Y:=Msg.Line;
  LogCaretXY.X:=Msg.Column;

  OpenFlags:=[ofOnlyIfExists,ofRegularFile];
  if MainBuildBoss.IsTestUnitFilename(Filename) then begin
    SearchedFilename := ExtractFileName(Filename);
    Include(OpenFlags,ofVirtualFile);
  end else begin
    SearchedFilename := FindUnitFile(Filename);
    if not FilenameIsAbsolute(SearchedFilename) then
      Include(OpenFlags,ofVirtualFile);
  end;

 

posted on 2024-09-30 14:03  秋·风  阅读(29)  评论(0编辑  收藏  举报