首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

D7移植到Delphi2009,TStringGrid DrawCell使用DrawText时出现乱码,请问咋回事

2012-05-09 
D7移植到Delphi2009,TStringGrid DrawCell使用DrawText时出现乱码,请教怎么回事?代码在下面,在Delphi7里是

D7移植到Delphi2009,TStringGrid DrawCell使用DrawText时出现乱码,请教怎么回事?
代码在下面,在Delphi7里是完全没有问题的,但把代码移植到2009后,发现DrawText的中文会出现乱码,而如果没有中文只有英文和数字,则只显示第一个字符,请问这是怎么回事?如何解决??

procedure TfrmSick.stringgridInfoDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  r:TRect;
  a:TGridRect;
begin
  with TStringGrid(Sender).Canvas do
  begin
  if ((ARow=TStringGrid(Sender).Row)) then begin
  Brush.Color := $00FAE2C0;
  FillRect(rect);
  SetRect(r,Rect.Left+2,Rect.Top+4,Rect.Right,Rect.Bottom);
  Font.Color:=clBlack;
  DrawText(Handle,PAnsiChar(TStringGrid(Sender).Cols[acol][arow]),-1,R,DT_LEFT or DT_WORD_ELLIPSIS);
  end;
  end;  
end;

[解决办法]
你先要确定PAnsiChar(TStringGrid(Sender).Cols[acol][arow])得到的是正确的结果,D7是ansi D2009是 unicode,一般处理不对就是乱码。

热点排行