我用了如下两种方法都发生错误,请问还有没有其他方法。
错误信息:interface not support;
procedure TfDrcgdd.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
begin
   if DSBC.DataSet.FieldByName('Amount').AsFloat = DSBC.DataSet.FieldByName('rece_amou').AsFloat then
   begin      DBGrid1.Canvas.Font.Color := clRed;
      DBGrid1.DefaultDrawDataCell(Rect, Field, State);   end;
end;procedure TfDrcgdd.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DSBC.DataSet.FieldByName('Amount').AsFloat = DSBC.DataSet.FieldByName('rece_amou').AsFloat then
  begin
    DBGrid1.Canvas.Font.Color:=clred;
    DBGrid1.Canvas.Brush.Color:=clblue;
    DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
  end;
end;

解决方案 »

  1.   

    感觉第二种方法不会有问题。感觉会不会是ASFLOAT的问题?是不是要加个四舍五入
      

  2.   

    如果说有错误的话又可能是你的数据的问题(可能是空值等异常)吧,试试下面的:
    procedure TfDrcgdd.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
    begin
    try
       if DSBC.DataSet.FieldByName('Amount').AsFloat = DSBC.DataSet.FieldByName('rece_amou').AsFloat then
        DBGrid1.Canvas.Font.Color := clRed;
    except
        DBGrid1.Canvas.Font.Color := clwhite;//可以根据需要定义
    end;
          DBGrid1.DefaultDrawDataCell(Rect, Field, State);
    end;
    //编译之后运行编译的程序绝对不会有问题了