Delphi built-in QuickReport reporting system provides powerful support for our fast production reports. For some simple reports, including longitudinal grouping multi-headed reports, we have little to write a code, you can easily complete the production of the report. But for the transverse packets shown in the drawings, we also need to write some code to control the print format of the report. This article is an example of the report shown as an example, and introduces the production methods and techniques of the horizontal group report.
First add a report form QRFORM1, add report control quickrep1 on the form, set its bands attribute, enable properties such as title, head, table details, and feet. Add Adoconnection1 connection controls and two Adodataset controls on the report form, named AdodatasetShqk and Adodataset1, respectively. The Adoconnection1 is connected to the database connection, and the AdodataStSHQK is bound to a data sheet that will be displayed and printed. The data set must add a permanent field. Then use QRSHAPE to tell the heads and details of the report. Among them, the Shape property of the horizontal line is set to QRShorline, Height = 1; the shape property of the vertical line is set to QRSVERTLINE, WIDTH = 1, vertical line dividing each field, generating longitudinal table line. The key issue here is: How to generate a horizontal grouping of report records? In order to achieve the purpose of the code control, we placed the horizontal QRSHAPE100 above the "Sequence" "Road Name" in the "Damage Situation" "Damage" "Damage Time" "area", place the horizontal direction under the entire Detailband QRSHAPE300. Place QRLABEL in Detailband, named QRLabelxh and QRLabeldlmc, and place QrDbText in "corruption" "corruption time" "area" position, respectively corresponds to the corresponding field. The principle of realizing the transverse group is to determine in the BEFOREPRINT event of the report Detailband. If the "serial number" "Road Name" record is the same as the previous record, it does not print QRSHAPE100 (whims whose width = 0), otherwise print. If the report prints to the end of this page or prints all records, print QRSHAPE300, otherwise the width of QRSHAPE300 is 0, that is, no print. Property of the design phase is about the control: QuickRep1.Dataset = ADODataSetRptShqk, ADODataSetShqk and ADODataSet1 of Connection = ADOConnection1, ADODataSetShqk CommandText property required to complete the SQL statement Select ... from ...; ADODataSet1 Active property to False. Finally, add code qrform1.quickrep1.preview; and qrform1.quickrep1.print; preview, or direct print report on the main form.
Unit report1; interfaceuses ... type ... var qrform1: tQrform1; oldstr: string; linesperpage: integer; // Each page has been printed LinePerItem: integer; // Each horizontal group record number Tumori Linestotal: Integer; / / The total number of records that has been printed LINEDISPLAYITEM: INTEGER; / / This line displays the transverse packet public information adodataset1count: integer; // Each horizontal group record number ID: integer; // Transverse grouping sequence IMPLEMENTATION {$ r * .dfm} / / Custom Function: Determine if you print to this page Function TQRFORM1.ISPAGEFOOT (): boolean; begin result: = false; linesperpage: = linesperpage 1; {According to the report preview result, manually determine the number of records per page, this program Page 1 is 33 records, Other pages 36 records} if quickrep1.pagenumber = 1 dam If linesperpage = 33 THEN Result: = true; end else begin if linesperpage = 36 the reba; = true; END; END; // custom function: determining whether all records after printing function TQRForm1.isLastRecord (): boolean; begin ADODataSetRptShqk.Next; if ADODataSetRptShqk.Eof then result: = true else Begin ADODataSetRptShqk.Prior; result: = false; end; end;
// Initialize variables: procedure TQRForm1.QuickRep1BeforePrint (Sender: TCustomQuickRep; var PrintReport: Boolean); begin oldstr: = ''; LinesPerPage: = 0; LinePerItem: = 0; LinesTotal: = 0; LineDisplayItem: = 0; Id: = 0; adodataset1count: = 0;
/// written details of the report - lateral packet control under the conditions: procedure TQRForm1.DetailBand1BeforePrint (Sender: TQRCustomBand; var PrintBand: Boolean); var NewStr: string; begin LinesTotal: = LinesTotal 1; NewStr: = trim (ADODataSetRptShqk. FieldbyName ( 'dlmc') AsString); if newStr = oldStr then QRShape100.Width:. = 0 else begin ADODataSet1.CommandText: = 'select count (dlmc) as Count1 from rpt_Shqk where dlmc =' '' '' newStr ' '' '; ADODataSet1.Active: = True; ADODataSet1Count: = ADODataSet1.FieldByName (' Count1 ') AsInteger; ADODataSet1.Active: = False; LinePerItem: = LinePerItem ADODataSet1Count; LineDisplayItem: = LinePerItem - ADODataSet1Count div 2; QRShape100.. Width: = 285; oldStr: = trim (newStr); Id: = Id 1; end; if LinesTotal = LineDisplayItem then begin QRLabelXh.Caption: = InttoStr (Id); QRLabelDlmc.Caption: = trim (ADODataSetRptShqk.FieldbyName ( ' DLMC '); END ELSE BEGIN QRLABELXH.CAPTION: ='; QRLABELDLMC.CAPTION: = '; end; // According to the conditional line: Qrshape300.Width: = 0; // 1, if the output is over, the bottom line: if ISPagefoot () The begin Qrshape300.Width: = 697; linesperpage: = 0; End; // 2, if the record output is completed, the bottom line: if islastrord () Then Qrshape300. Width: = 697; end; procedure tqrform1.formClosequery (Sender: Tobject; var canclose: boolean); begin quickrep1.free; end;
Procedure tqrform1.quickrep1startpage (Sender: tcustomquickrep); begin adodatasetrptshqk.active: = true; end; end. Zhang Qing Email: zhangking@263.net