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);