delphi 如何在按钮上添加
procedureTfm_chWasteck.BitBtn2Click(Sender:TObject);beginsumADODS.Close;sumADODS.Comm...
procedure Tfm_chWasteck.BitBtn2Click(Sender: TObject);
begin
sumADODS.Close;
sumADODS.CommandText:='select sum(wh2) as 二楼仓库数,sum(wh5) as 五楼仓库数,sum(whsys) as 仓库数,sum(sys2) as 二楼转机纸数,sum(sys5) as 五楼转机纸数,sum([sys2+5]) as 两楼转机纸数,sum(syswh) as 系统总数,sum(differ) as 相差数 from fm_chwasteck';
sumADODS.open;//到这里是查询内容,下面是改变行颜色
if sumADODS.FieldByName('differ').AsCurrency>1 then
DBGrid2.Canvas.Brush.Color:=clWhite;
DBGrid2.DefaultDrawColumnCell(Rect,DataCol, Column, State);
end;
但是运行时提示错误:
[Error] U_chWasteck.pas(228): There is no overloaded version of 'Rect' that can be called with these arguments
[Error] U_chWasteck.pas(228): Undeclared identifier: 'State'
[Fatal Error] ym.dpr(30): Could not compile used unit 'U_chWasteck.pas'
请问如何添加才可以运行啊。 展开
begin
sumADODS.Close;
sumADODS.CommandText:='select sum(wh2) as 二楼仓库数,sum(wh5) as 五楼仓库数,sum(whsys) as 仓库数,sum(sys2) as 二楼转机纸数,sum(sys5) as 五楼转机纸数,sum([sys2+5]) as 两楼转机纸数,sum(syswh) as 系统总数,sum(differ) as 相差数 from fm_chwasteck';
sumADODS.open;//到这里是查询内容,下面是改变行颜色
if sumADODS.FieldByName('differ').AsCurrency>1 then
DBGrid2.Canvas.Brush.Color:=clWhite;
DBGrid2.DefaultDrawColumnCell(Rect,DataCol, Column, State);
end;
但是运行时提示错误:
[Error] U_chWasteck.pas(228): There is no overloaded version of 'Rect' that can be called with these arguments
[Error] U_chWasteck.pas(228): Undeclared identifier: 'State'
[Fatal Error] ym.dpr(30): Could not compile used unit 'U_chWasteck.pas'
请问如何添加才可以运行啊。 展开
2个回答
展开全部
procedure Tfm_chWasteck.BitBtn2Click(Sender: TObject);
begin
sumADODS.Close;
sumADODS.CommandText:='select sum(wh2) as 二楼仓库数,sum(wh5) as 五楼仓库数,sum(whsys) as 仓库数,sum(sys2) as 二楼转机纸数,sum(sys5) as 五楼转机纸数,sum([sys2+5]) as 两楼转机纸数,sum(syswh) as 系统总数,sum(differ) as 相差数 from fm_chwasteck';
sumADODS.open;//到这里是查询内容,下面是改变行颜色
//---------------------------------------------------------------------------------//
//这部分放在dbgrid的DrawColumnCell事件里面
if sumADODS.FieldByName('differ').AsCurrency>1 then
DBGrid2.Canvas.Brush.Color:=clWhite;
DBGrid2.DefaultDrawColumnCell(Rect,DataCol, Column, State);
//--------------------------------------------------------------------------------//
end;
可以参考隔行显示不同颜色背景的代码,你只需要更改其中的条件和背景颜色就可以了。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (IBTable1.RecNo mod 2) = 0 then
(Sender as TDBGrid).Canvas.Brush.Color := clGray //定义背景颜色:灰
else
(Sender as TDBGrid).Canvas.Brush.Color := clWhite; //定义背景颜色:白
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
begin
sumADODS.Close;
sumADODS.CommandText:='select sum(wh2) as 二楼仓库数,sum(wh5) as 五楼仓库数,sum(whsys) as 仓库数,sum(sys2) as 二楼转机纸数,sum(sys5) as 五楼转机纸数,sum([sys2+5]) as 两楼转机纸数,sum(syswh) as 系统总数,sum(differ) as 相差数 from fm_chwasteck';
sumADODS.open;//到这里是查询内容,下面是改变行颜色
//---------------------------------------------------------------------------------//
//这部分放在dbgrid的DrawColumnCell事件里面
if sumADODS.FieldByName('differ').AsCurrency>1 then
DBGrid2.Canvas.Brush.Color:=clWhite;
DBGrid2.DefaultDrawColumnCell(Rect,DataCol, Column, State);
//--------------------------------------------------------------------------------//
end;
可以参考隔行显示不同颜色背景的代码,你只需要更改其中的条件和背景颜色就可以了。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (IBTable1.RecNo mod 2) = 0 then
(Sender as TDBGrid).Canvas.Brush.Color := clGray //定义背景颜色:灰
else
(Sender as TDBGrid).Canvas.Brush.Color := clWhite; //定义背景颜色:白
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询