Print TDBGRID content ---- Method 1Procedure PrintDbGrid (Dataset: TDataSet; DBGRID: TDBGRID; Title: String); Varpointx, Pointy: Integer; Screenx: Integer; i, lx, ly: integer; px1, py1, px2, py2: integer; RowPerPage, RowPrinted: integer; ScaleX: Real; THeight: integer; TitleWidth: integer; SumWidth: integer; PageCount: integer; SpaceX, SpaceY: integer; RowCount: integer; beginPointX: = Round (GetDeviceCaps (printer.Handle, LOGPIXELSX ) /2.54); Pointy: = Round (Printer.Handle, Logpixelsy) / 2.54); Screenx: = Round (Screen.Pixelsperinch / 2.54); scalex: = pointx / screenx; rowprinted: = 0; sumWidth: = 0 Printer.Begindoc; with printer.canvas do beg, dataset.disablecontrols; dataset.first; theight: = round (TEXTHEIGHT (TEXTHEIGHT ('I') * 1.5); // Set the height of each line of 1.5 times Spacey: = Round (TEXTHEIGHT ('I') / 4); Spacex: = Round (TEXTWIDTH (I ') / 4); RowPerpage: = Round ((Printer.pageHeight-5 * Pointy) / theight); // Upper and lower edges 2 cm ly: = 2 * Pointy; PageCount: = 0; while not dataset.eof do begin if (rowprinted = rowperpage) or (rowprinted = 0) THEN BEGIN IF Rowprinted <> 0 THEN PRINTER.NEWPAGE; rowprinted: = 0; PageCount: = PageCount 1; font.name:= 'Song body'; font.size: = 16; font.style :=Font.Style [fsbold]; lx: = round Printer.pagewidth-textWidth (Title) / 2); ly: = 2 * Pointy; TextOut (LX, LY, TITLE); font.size: = 11; font.style :=Font.Style-[fsbold]; lx : = Printer.PageWidth-5 * PointX; ly: = Round (2 * PointY 0.2 * PointY); if RowPerPage * PageCount> DataSet.RecordCount then RowCount: = DataSet.RecordCount else RowCount: = RowPerPage * PageCount; TextOut (lx , LY, 'First'
INTSTOSTR (PageCount-1) 1) '-' INTOSTR (ROWCOUNT) 'Bar, a total' INTOSTR (Dataset.RecordCount) 'strip'); lx: = 2 * PointX; ly: = Ly theight * 2; py1: = ly-spacey; if rowcount = Dataset.Recordcount the py2: = py1 theight * (RowCount-RowPerpage * (PageCount-10) 1) ELSE PY2: = Py1 Theight * (RowPrPage 1); sumWidth: = lx; for i: = 0 to dbgrid.columns.count-1 do begin px1: = sumwidth-spaceX; px2: = sumwidth; moveto (px1, py1); lineto (PX2, PY2); TitleWidth: = TextWidth (dbgrid.columns [i] .title.caption); lx: = round (SUMWIDTH (DBGRID.COLUMNS [I] .width * scalex-titlewidth / 2); Textout (lx, ly, dbgrid.columns [i] .title.caption; sumWidth: = round (sumwidth dbgrid.columns [i] .width * scalex) Spacex * 2; end; px1: = sumwidth; // draw last vertical line PX2: = Sumwidth MoveTo (PX1, PY1); LINETO (PX2, PY2); PX1: = 2 * Pointx; // Draws the first horizontal PX2: = Sumwidth; PY1: = LY-Spacey; PY2: = LY-Spacey; Moveto ( PX1, PY1); LINETO (PX2, PY2); PY1: = Py1 theight; py2: = py2 theight; MoveTo (PX1, PY1); LINETO (PX2, PY2); END; LX: = 2 * Pointx; ly : = ly theight; px1: = lx; px2: = sumwidth; py1: = ly-spacey theight; py2: = ly-spacey theight; Moveto (PX1, PY1); LINETO (PX2, PY2); for i : = 0 to dbgrid.columns.count-1 Do Begin Textout (lx, ly, dataset.fieldbyName (dbgrid.columns [i] .fieldname) .sstring; lx: = round (lx dbgrid.columns [i]. Width * Scalex Spacex * 2);