procedure TfFrmOrd.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
Var
  AText:String;
  I:Integer;
begin
  inherited;
  IF BasDM.FindOrdQry.fieldByName('Proc_Qty').Asfloat>0 then 
 //Proc_Qty是生产数量字段,显示本窗体的时候Proc_Qty在 DBGrid1不能看到,能正确着色.....
  begin
    AText:=Column.Field.AsString ;  //当移动DBGrid1横条出现 Proc_Qty的时候报地址错
    DBGrid1.Canvas.Font.Color:=clBlack;
    DBGrid1.Canvas.Font.Height:=12;
    DBGrid1.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+
    (Rect.Bottom-Rect.Top-DBGrid1.Canvas.TextHeight(AText)) div 2,AText);
  end
  Else
  begin
    DBGrid1.Canvas.Font.Color :=clBlue;
    DBGrid1.Canvas.Font.Height:=12;
    DBGrid1.Canvas.TextRect(Rect,Rect.left+1,Rect.top+1,Column.Field.AsString);
  end;
end;

解决方案 »

  1.   

    在http://61.186.252.131/的Delphi板块中搜索“DBGrid 颜色”,参考一下
      

  2.   

    procedure TfFrmOrd.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      inherited;
      IF BasDM.FindOrdQry.fieldByName('Proc_Qty').Asfloat>0 then 
     //Proc_Qty是生产数量字段,显示本窗体的时候Proc_Qty在 DBGrid1不能看到,能正确着色.....
      begin
        DBGrid1.Canvas.Font.Color := clBlack;
        DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end
      Else
      begin
        DBGrid1.Canvas.Font.Color := clBlue;
        DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
    end;