procedure CalcTotalAmt(CalcDbg: TDbGrideh;
FieldName: array of string; valType: array of TFooterValueType);
var
i, iLen: integer;
CalcColumnEh: TColumnEh;
begin
if high(valType) <> high(FieldName) then
begin
showMessage('合计函数失败,字段数与字段类型描述数不符!');
exit;
end;
CalcDbg.FooterRowCount := 1;
calcDbg.FooterColor := clBtnFace;
iLen := high(ValType);
for i := 0 to iLen do
begin
CalcColumnEh := CalcDbg.FieldColumns[FieldName];
if CalcColumnEh <> nil then
begin
if ValType = fvtStaticText then
begin
CalcColumnEh.Footer.ValueType := fvtStaticText;
CalcColumnEh.Footer.Value := '合计:';
end
else
if ValType = fvtSum then
begin
CalcColumnEh.Footer.ValueType := fvtSum;
CalcColumnEh.Footer.FieldName := FieldName;
end
else
if ValType = fvtCount then
begin
CalcColumnEh.Footer.ValueType := fvtCount;
CalcColumnEh.Footer.FieldName := FieldName;
end;
CalcColumnEh.Footer.Font.Color := clblue;
end;
end;
CalcDbg.SumList.Active := true;
CalcDbg.SumList.RecalcAll;
end;
调用:CalcTotalAmt(dbgrid,['字段1','字段2'],[fvtStaticText,fvtsum])