Quick report general report printing program

Source: Internet
Author: User
Tags field table

 

Unit unit_qreport_lxr;
{
Module name: general report printing
Author: Yin Shuguang
Development Date:
Website: www.sinoprise.com
This program applies to the GNU protocol.
The following is how to use it:
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)
Then 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;
End;

VaR
Qreport_lxr: tqreport_lxr;

Implementation

{$ R *. DFM}
File: // vertical bar
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 column in the dataset; true: false: not printed
VaR
Field_vertical_space_div_2, field_horizontal_space_div_2: integer; file: // The vertical distance of the field is 1/2, and the horizontal distance of the field is 1/2.
Field_width, field_height: integer; // The width of the field, the height of the field
Columns_count: integer; // number of fields displayed in each row
Current_row, current_col: integer; // number of rows and columns output now; first row, column 1,
Rp_left, rp_width: integer; // left margin from the beginning of the report, and the report width
Averticallineposition: array of integer; // records the position of the split line in each column
Hafn: integer; file: // start Number of the field output Column

Qr: tqrshape; file: // mark the report
La: tqrlabel; file: // field table
Te: tqrdbtext; file: // field content

I: integer; // cyclic variable

Begin

File: // whether the dataset is opened
If (objdataset. Fields. Count <= 0) then
Begin
Messagedlg ('Please first query and then print the report! ', Mtinformation, [mbyes], 0 );
Result: = false;
Exit;
End;
File: // set the Initial Value
Field_vertical_space_div_2: = 5; file: // 1/2 of the vertical distance of the field
Field_horizontal_space_div_2: = 5; file: // the horizontal distance of the field is 1/2.
Field_width: = 100; file: // The width of the field
Field_height: = 17; file: // field height
Rp_width: = thedetailband. width; file: // report width
Rp_left: = 0; file: // left margin of the report
Columns_count: = rp_width Div (field_width + field_horizontal_space_div_2 * 2); // The number of fields displayed in each row
Setlength (averticallineposition, columns_count + 1 );
File: // record set on this page
Dataset: = objdataset;

File: // Note: whether to discard the first column in objdataset
If havefirstcol
Then hafn: = 0
Else hafn: = 1;

File: // output field Header
File: // The upper horizontal line
Qr: = gethl;
Qr. Parent: = thecolumnheaderband;
Qr. Top: = 0;
Qr. Left: = rp_left;
Qr. Width: = rp_width;

Averticallineposition [0]: = rp_left;

Current_row: = 1; // number of rows output now, first row 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 the vertical line
Averticallineposition [current_col]: = current_col * (field_width + current_col * 2 );

If current_col = columns_count
Then begin
Current_col: = 1;
Current_row: = current_row + 1;
End
Else current_col: = current_col + 1;
End;

File: // modify the position of the last column
Averticallineposition [high (averticallineposition)]: = rp_width;
File: // draw a vertical line on the header
For I: = low (averticallineposition) to high (averticallineposition) Do
Begin
Qr: = getsl;
Qr. Parent: = thecolumnheaderband;
Qr. Top: = 0;
Qr. Left: = averticallineposition [I];
Qr. Height: = thecolumnheaderband. height;
End;
File: // horizontal line above the report section
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 Part
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: // draw a vertical line on the Content Part
For I: = low (averticallineposition) to high (averticallineposition) Do
Begin
Qr: = getsl;
Qr. Parent: = thedetailband;
Qr. Top: = 0;
Qr. Left: = averticallineposition [I];
Qr. Height: = thedetailband. height;
End;
Qr: = gethl;
Qr. Parent: = thedetailband;
Qr. Top: = thedetailband. height;
Qr. Left: = rp_left;
Qr. Width: = rp_width;
Result: = true;
End;
End.

This article is formerly known as the Quickreport universal print program. This is a modified version. It mainly adds table display on the report and optimizes the program (www.sinoprise.com ).

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.