得,给你写个例子,已经测试通过。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGridEh;
type
TForm1 = class(TForm)
DBGridEh1: TDBGridEh;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
ADOQuery1zrs: TIntegerField;
ADOQuery1Ars: TIntegerField;
ADOQuery1Brs: TIntegerField;
ADOQuery1SumA: TCurrencyField;
ADOQuery1SumB: TCurrencyField;
Button1: TButton;
ADOQuery2: TADOQuery;
procedure ADOQuery1CalcFields(DataSet: TDataSet);
procedure Button1Click(Sender: TObject);
procedure ADOQuery1SumAGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ADOQuery1CalcFields(DataSet: TDataSet);
begin
DataSet.FieldByName('SumA').AsString:=format('%.2f',[DataSet.fieldbyname('Ars').AsCurrency/DataSet.fieldbyname('Zrs').AsCurrency]);
DataSet.FieldByName('SumB').AsString:=format('%.2f',[DataSet.fieldbyname('Brs').AsCurrency/DataSet.fieldbyname('Zrs').AsCurrency]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not adoquery1.Active then adoquery1.Open;
with adoquery2 do
begin
close;
sql.Text:='select sum(Zrs),sum(Ars),sum(Brs) from cal';
open;
dbgrideh1.Columns[2].Footer.value:=format('%.2f',[(fields[1].ascurrency/fields[0].ascurrency)*100])+'%';
dbgrideh1.Columns[4].Footer.value:=format('%.2f',[(fields[2].ascurrency/fields[0].ascurrency)*100])+'%';
end;
end;
procedure TForm1.ADOQuery1SumAGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
Text:=floattostr(Sender.AsCurrency*100)+'%';
end;
end.