unit unit_QReport_lxr; {module name: Universal Report Author: Yin Shuguang Development Date: 2004-07-15 Website: www.sinoprise.com This procedure applies to the following protocol using GNU method: procedure TFrm_sbcx_yin.BitBtn_xxxx_dyClick (Sender: TObject); VAR QP: TQREPORT_LXR; Begin QP: = TQREPORT_LXR.CREATE (Self); QP.BB_TITLE.CAPTION: = 'Device Category Query'; if qp.bb_prepare (AdoQuery_xxxx, false) The begin qp.prepare; qp.preview; qp. Hide; end; qp.free; end;} interface
Uses Windows, Sysutils, Messages, Classes, Graphics, Controls, Stdctrls, ExtCtrls, Forms, Quickrpt, Qrctrls, DB, AdoDB, Dialogs
type TQReport_lxr = class (TQuickRep) theDetailBand: TQRBand; TitleBand1: TQRBand; bb_title: TQRLabel; theColumnHeaderBand: TQRBand; private function GetSL (): TQRShape; function GetHL (): TQRShape;
Public function bb_prepare (ObjDataSet: TDataSet; Havefirstcol: Boolean: boolean;
VAR Qreport_LXR: TQREPORT_LXR;
IMPLEMentation
{$ R * .dfm} file: // vertical line function tqreport_lxr.getsl (): tqrshape; begin result: = tqrshape.create (self); result.shape: = QrsvertLine; Result.Width: = 3; end; file : // Horizontal line function tqreport_lxr.gethl (): tqrshape; begin result: = tqrshape.create (self); result.shape: = qrshorline; result.height: = 3; end;
function TQReport_lxr.bb_prepare (objDataSet: TDataSet; haveFirstCol: boolean): boolean; file: // haveFirstCol: boolean; whether to print the first row of the dataset, true printing, false not print var Field_Vertical_space_div_2, Field_Horizontal_space_div_2: integer; file: // The vertical distance of the field, the horizontal distance of the field, the horizontal distance of the field, the width of the field, the width of the field, the height of the field, the field of the field, the field of the field displayed in each row, current_row, current_col: integer // Now output the first few lines, columns; first line, listing 1, rp_left, rp_width: integer; // Report start left distance, the width of the report is aVerticalLinePosition: array of integer; // Record the split line of each column Location Hafn: Integer; File: // Field Output Column Start No. QR: TQRShape; File: // Online LA: TQRLABEL; File: // Field Tag TE: TQRDbText; File: // Field Content
I: integer; // cycle variable
Begin
File: // Does the data set Open if (ObjdataSet.fields.count <= 0) Then Begin Messagedlg ('Please query first, then print the report!', mtinformation, [mbyes], 0); result: = false; EXIT; END; File: // Setting the initial value field_vertical_space_div_2: = 5; File: // Field_HORIZONTAL_SPACE_DIV_2: = 5; File: // Level 1/2 Field_Width: = 100; File: // Field Width Field_Height: = 17; File: // Field High RP_WIDTH: = theDetailband.width; File: // Report Width RP_LEFT: = 0; File: // Retent The beginning of the Report The left edge of Column_count: = RP_WIDTH DIV (Field_Width Field_Horizontal_Space_DIV_2 * 2); // The field of the field displayed in each line setlength (AverticalLinePosition, Column_Count 1); File: // Record set of records on this page DataSet: = objDataSet;
File: // Note: Whether to abandon the first column IF Havefirstcol the Hafn: = 0 else hafn: = 1;
File: // Output Field Header File: / / The horizontal lines on the upper side QR: = gethl; qr.Parent: = thecolumnheaderband; qr.top:=0; qr.LEFT: = rp_left; qr.Width: = rp_width; averticallinePosition [0]: = rp_left;
Current_row: = 1; // now output the first few lines, the first behavior 1 Current_col: = 1; for i: = hafn to objDataSet.FieldCount-1 do begin theColumnHeaderBand.Height: = current_row * (Field_height Field_Vertical_space_div_2 * 2); file : // Calculate the height of the field header LA: = tqrlabel.create (self); la.parent: = TheColumnHeaderBand; la.caption: = objDataSet.fields [i] .fieldname; la.Width: = field_width; la.height : = Field_height; la.Left: = (2 * Current_col-1) * Field_Horizontal_space_div_2 (Current_col-1) * Field_width; la.Top:=Current_row*Field_Vertical_space_div_2 (Current_row-1)*Field_height;
File: // Calculate the position of vertical line AverticalLinePosition [current_col]: = current_col * (Field_Width Current_col * 2);
If current_col = columns_count dam current_col: = 1; current_row: = current_row 1; end else current_col: = current_col 1;
File: // Modify the last list AverticalLinePosition]: = rp_width; file: // Drain the vertical line on the header for i: = low (averticallineposition) Do Begin QR: = Getsl Qr.Parent: = thecolumnheaderband; qr.top:=0; qr.left: = averticalLinePosition [i]; qHEight: = thecolumnheaderband.Height; End; File: // Report part of the horizontal line QR: = gethl Qr.Parent: = theDetailband; qr.top:=0; Qr.Left: = rp_left; qr.width: = rp_width;
CURRENT_COL: = 1; current_row: = 1;
for i: = hafn to objDataSet.FieldCount-1 do begin file: // calculate the height of the content portion theDetailBand.Height: = current_row * (Field_height Field_Vertical_space_div_2 * 2); te: = TQRDBText.Create (self); te.DataSet : = Objdataset; TE.Parent: = thedetailband; te.datafield: = objDataSet.fields [i] .fieldname; te.width: = field_width; te.height: = field_height; te.left: = (2 * Current_col-1 ) * Field_Horizontal_space_div_2 (Current_col-1) * Field_width; te.Top:=Current_row*Field_Vertical_space_div_2 (Current_row-1)*Field_height; te.AutoStretch: = true; if Current_col = Columns_count then begin Current_col: = 1; current_row: = current_row 1; END ELSE CURRENT_COL: = CURRENT_COL 1; END; File: // Drain the vertical line in the content part for i: = low (averticallineposition) to high (averticallineposition) Do Begin qr: = getsl; qr.parent: = theDetailband Qr.top:=0; Qr.Left: = averticallineinePosition [i]; qHEight: = theDetailband Height; end; qr: = gethl; qr: qr.top: = thedetailband.height; qr.left: = rp_left; qr.Width: = rp_width; result: = true; end; end;
This article: QuickReport universal printing program, this is a modified version, mainly increasing the table display on the report, and the program has also been optimized (www.sinoprise.com).