用数据库来统计就OK了,看下面的代码: <br> query:=TADOquery.Create(self);<br> query.Connection:=frmbase.conDB;<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Text:='select count(*) as 总数,sum(sqjc) as 上结存,sum(bqjh) as 本进货,sum(bqxs) as 本销售,'+<br> 'sum(bqth) as 本退货,sum(bqjc) as 本结存,sum(s) as s,sum(m) as m,sum(l) as l,sum(xl) as xl,sum(xxl) as xxl'+<br> ' from jx_tab where uid='+inttostr(nodedata(tree1.Selected.Data).ID) ;<br> query.Open;<br> <br> //合计保存<br> agsum[0]:='合计('+query.fieldbyname('总数').AsString+'种)';<br> agsum[1]:=query.fieldbyname('上结存').AsString;<br> agsum[2]:=query.fieldbyname('本进货').AsString;<br> agsum[3]:=query.fieldbyname('本销售').AsString;<br> agsum[4]:=query.fieldbyname('本退货').AsString;<br> agsum[5]:=query.fieldbyname('本结存').AsString;<br> agsum[6]:='';<br> agsum[7]:=query.fieldbyname('s').AsString;<br> agsum[8]:=query.fieldbyname('m').AsString;<br> agsum[9]:=query.fieldbyname('l').AsString;<br> agsum[10]:=query.fieldbyname('xl').AsString;<br> agsum[11]:=query.fieldbyname('xxl').AsString;