秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
lazarus linux使用StringGrid和DBGrid等控件时,如果单元格内容包含#13时会显示乱码.

  修改/lazarus/lcl/interfaces/gtk2/gtk2devicecontext.inc行1303行开始的:

procedure TGtkDeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
  X, Y: Integer; FGColor, BGColor: PGdkColor);

添加红字的代码,重新编译应用就可以

procedure TGtkDeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
  X, Y: Integer; FGColor, BGColor: PGdkColor);
var
  WidgetCont: PPangoContext;
  NewMatrix: TPangoMatrix;
  OldMatrix: PPangoMatrix;
  renderer: PGdkPangoRenderer;
  Direction : TPangoDirection;
  AFont: PGdiObject;
  i:integer;

  procedure SetColors(AFGColor, ABGColor: PGdkColor); inline;
  begin
    gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_FOREGROUND, AFGColor);
    gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_UNDERLINE, AFGColor);
    gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_STRIKETHROUGH, AFGColor);
    gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_BACKGROUND, ABGColor);
  end;
  
begin
  for i:=0 to length(AText)-1 do
  begin
    if ord(AText[i])<32 Then AText[i]:=#32;
  end;
  AFont := GetFont;
  SetLayoutText(AFont^.GDIFontObject, AText, ALength);

posted on 2023-03-03 16:20  秋·风  阅读(283)  评论(0编辑  收藏  举报