有很多人问为什么只支持StringGrid,不支持dbGrid,dbGrideh等等,这里我需要说明的是StringGrid只是 一个存放临时数据的载体,供CallDllPrint接受数据源而已。大家只要看了zyprint.pas里的CallDllPrint函数就清楚了。 ----------dbGrid,dbGrideh,都是和数据集绑定的,只需把数据集的数据填空到stringGrid里就行了。 var tempGrid:TStringGrid; //数据表 R,C:Integer; //行,列 Ds:TADODataSet; begin try tempGrid:=TStringGrid.Create(nil); //因为只是一个存放临时数据的载体,所以可以动态创建和释放,不需要界面上显示 tempGrid.Hint:='商品入库单'; Ds:=TADODataSet.Create(nil); Ds.Connection:=AdoConn; Ds.CommandText:='select * from a '; Ds.Open; //将数据填充入tempGrid(将数据存放到载体) if not Ds.Eof or not Ds.Bof then begin tempGrid.RowCount:=ds.RecordCount+1; tempGrid.ColCount:=ds.FieldCount; for C:=0 to ds.FieldCount -1 do begin Ds.First; tempGrid.Cells[C,0]:=ds.FieldDefs[c].Name; for R:=1 to Ds.RecordCount do begin tempGrid.Cells[c,r]:=Ds.Fields[c].AsString; ds.Next; end; end; end; CallDllPrint('zyPrintcrt.dll',Application,AdoConn,tempGrid,nil,nil,nil,nil,nil,nil,Self.Caption,pState); //传入tempGrid(数据载体)调用打印 finally tempGrid.Free;//释放 Ds.close; Ds.free; end; end; 这里演示的是将Ds:TADODataSet 数据存在到tempGrid里面,希望能举一反三。