In-depth QuickReport (1)

zhaozj2021-02-12  217

In-depth QuickReport (1)

Author: Dongwei Chun

(This article has been published in the "9CBS Development Master" in the first, second and third phases, and the requirements of the majority of netizens, published in the 9CBS Author's document, which is slightly modified, but only here, not After 9CBS or author I agree with any individual and website must not be reproduced, you can take it, otherwise any of the consequences involved in copyright.

The report is one of the basic components of the database application, and the complete database application will always provide a report function. The QuickReport component is provided in C Builder compared to traditional database application design tools, making C Builder's database functions greatly enriched.

QuickReport is a set of controls designed for reports in Norwegian Qusoft AS, which is used for reports, and the QuickReport we use in C Builder compared to the professional QUICKREPORT, but for us. Said that just make full use of her, you can set the powerful, moderate data report, the most important thing is that she doesn't need us to buy.

In fact, QuickReport is not difficult, but the content of this is too small, and her help document is not very good, let C Builder enthusiasts who want to learn QuickReport can't find a correct, suitable method. If you want to know her, use her, let me help you know this demon woman, if this article can help you, it is my biggest happiness!

Part 1: QuickReport Basic Knowledge

The Qusoft's Report Component Series introduced by BCB, which includes multiple components. First, it is necessary to briefly understand the basic location and function of these twenty-three components.

I. Introduction to Component Function

The above two figures are all components of the QuickReport component page, and it is not less than 23 of the above BCB6.

The following table is a simple introduction to the use function of each control in the following table.

1) QuickRep

With coordinates, as other report controls, such as tqrband, you can automatically add various types of TQRBAND through its Band properties.

Important properties (Properties)

Instructions for use

DataSet

Connect data source, generally the name of the ADO / BDE connection component

Page

Paper settings can be expanded

Bottommargin

10.0mm

Report under boundaries

Columns

1

The number of reports, the default is 1 column

ColumnSpace

0.0mm

The report field is effective with the bar interval, and the columns value is more effective than 1.

LEFTMARGIN

10.0mm

Report left boundary size

Length

210.0mm

Report length size, associated with PaperSize

Orientation

POPORTRAITPOLANDSCAPE

In the direction of the report, there are two values ​​below: direct printing poporit, transparent print Polandscape

PAPERSIZE

A4

Report print paper size

Rightmargin

10.0mm

Report right boundary dimensions

Ruler

True

Report ruler display

Topmargin

10.0mm

Report on the boundary size

Width

297.0mm

Report width dimensions, related to Papersize settings

PrinterSetting

COPIES

1

Report replication

Duplex

False

Double printing

Firstpage

0

Report print start page

Lastpage

0

Report print termination page

Outputbin

Auto

Report output type

ReportTitle

Report preview print heading

Units

mm

Report design phase display ruler unit

2) Qrsubdetail

Create a master / details (Master / Detail) report, connect the details of the detailed file

3) QrstringsBand

A component that reads the key value in the TSTRINGS can be established. There is an items attribute in this component, if Items is a value (a row, a business office) is not, then the components above will not work. When there is a few lines in the String List Editor, the contents on the component are repeated several times. When only one line of content, she is the same as a detailband; while more, it is almost almost, that is, repeating the visual components within the section (several lines a few times), then the next one is repeated. For example, three lines, that is the first data to three lines, then the second data is three lines, then until the last

4) Qrband

What should be displayed in different locations in the report, it can put it on it

5) qrchildband

Base items in the report. He has a ParentBand property that you have to connect him with other Band, and only the components arranged in her are valid. It is directly that there is already a Band and you still need a such component, then use her.

6) qrgroup

Make logically packets in the report. When you connect a few Datasets to the report, you can operate the DataSet via Groups.

7) qrlabel

Print static text (ie, do not change according to the database value), like TLABEL. The content of CAPTION is printed; AutostRetch is a Boolean variable. When the tag title cannot be printed within the setting range, the attribute will work. If true, the report will continue to print the text without printing, and other prints The text will move backwards later, but in turn, the exceril is not printed.

8) qrdbtext

Components with text features that display linkage data sources in the report

9) QRexpr

There are components that display statements or calculate the representative values ​​in the report.

10) QrsysData

Components with display system information in the report

11) qrmemo

Display components of the note text in the report

12) QRexPrmemo

In the report is a mixed component of TQREXPR and TQRMEMO

13) Qrrichtext

Components with display area text features in the report

14) qrdbrichtext

Components with regional text features that have sources of display links in the report

15) QRSHAPE

Treat geometry components in the report, such as square, rounded square, ellipse

16) qrimage

Display static pictures in the report, including (BMP, WMF, ICON)

17) qrdbimage

Display images received from the database in the report

18) qrcompositerEport

Connect the relevant report components regarding the report, the components used to create a mixed report can be connected together, form a report together.

19) qrpreview

Built a self-order preview report component in the execution phase

20) QRTextFilter

Output report content to ASCII Text file

21) qrcsvfilter

Output report content to the CSV file

22) QRHTMLFILTER

Output report content to HTML files

23) qrchart

Chart tools that can be applied to reports

Second, component relationship table

The following figure illustrates the connection and relationship between the QUICKREPORT related components:

┌ADOTABLE <= | ┌QRCHilderBand┐

Database <= ado <= │ | <===== Quickrep <===== ├QRband │ <=== visualization component

└adoquery <= | └QRStringBand ┘

Database ADO Engine Report Container Component BAND Section (Container) Visual Control (Display)

Note: The visualization component must be arranged on the corresponding TQRBAND section, otherwise you will not get the content to be displayed. The BDE engine is similar to this. He is not the same as the ADO is not the same as the library link, there is no impact on QuickReport.

Sometimes some friends don't care carefully on the form, but not directly placed on each BAND section in the TQUick component, when these components are moved to the segment you want to place, these components cannot be used. So you want to remember: Be sure to place the component on a fixed section and cannot move between the sections. We can see these components from Object TreeView, which is the same layer, of course, he can't work for tquickrep, only when he becomes a certain section of TquickRep (a BAND) next to the next layer, it can work. And be sure to put it in a section, don't mistaken it on tquickrep, if you put it directly on tquickrep, what will not be not available in your report?

Third, the maximum container TQUickReprep

The organization level in QuickReport is especially stricter. TquickRepRep is must have in the report component, and all BAND components must be placed on her. If each BAND zone is a small container, then she is a biggest container. Want to use QuickReport, tquickrep is definitely not only as a container similar to form, how to use her use of QUICKREPORT to play a critical role.

1) Main attributes:

DataSet is a TDataSet dataset type variable that sets the data set component object used by the report, and is the data set of the main report in the main / detail. If our report is to use the database, she must specify the name of the database connection tool, otherwise your program will not see the data in the database. Of course, in the connection component of the database, you must set Active to True, so that you can only open the database in the program run, and what will not see in the program design phase

RecordCount is the number of records recorded in the data set component object;

RecordNumber is the index of the recorded / displayed record (index of the first record is 0); RecordCount, the two attributes of the RecordNumber are only available after opening the dataset object, they can access.

If the reporter is successfully extracted from the data set component object, the attribute value of the Available is TRUE.

The State property is reported status information, which is an enumerated variable, which can have the following value:

QRAVAILABLE: Report resources are ready, you can preview or print;

Qrprepare: The report is being generated;

Qrpreview: Preview the report;

Qrprint: Print the report;

Qredit: I'm editing the report.

Description is a TStrings type property that can be used to save programmers' brief description of the report. Mainly a prompt role.

Page Properties is the most important properties in the TQUickRep component, which is a TQRPage type variable to set the page properties of the report. Report components provide her with a special editor. Use the shortcut menu Report Settings of the component to open the Page property editor window. On the Report Page Properties dialog box, you can set the size of the page, the border, columns, sections, etc. page. Of course, we can also click " " in front of the object viewer to expand all of its properties and set these properties separately. Where Pagersize is setting paper size, he is closely related to width, lonth, changing the value of Pagersize, and the values ​​of the back will also make corresponding changes. Similarly, when the two properties are changed, the value of Pagersize will also Make a corresponding change. We can change the direction of printing by changing the value of Orientation. Margins refers to the location of the report display in Pagersize. COLUMNS Attribute We must pay attention to it is a column setting. It is the same as the column setting in Word, no matter what the purpose, sometimes we have to divide the print content into two columns (or multi-column), then we will To use it, turn its value to 2 (or the actual number of columns), as for the distance between the column we are set by Column Space.

The Units property is used to set the display unit of the paper. We usually use mm (mm), of course, you have to know other comparisons can also be used, but I think it is best not to use other items.

2) Main methods and events

TQUickRep provides a large number of methods to achieve features of generating, previewing, and printing reports, however, it's a private member function, not allowed to access outside the class. When implementing report functions, applications often need to call Cancel, NewColumn, Preview, PreviewModal, PreviewModeless, Print, PrinterSetup, and ResetPageFootersize.

The CANCEL method is used to revoke the current operation, which is the same as True with the Cancelle property of the TQUickRep component object.

NewColumn, Print and PrinterSetup are related to printing. Where newcolumn is used to force the printer to start printing from the new bar, if the current column is the last column of the page, the method will automatically call the method newpage, start printing from the new page.

Preview, PreviewModal and PreviewModeless are used to preview reports.

These methods do not need any parameters.

TQUickRep A events can respond to events: AfterPreview, AfterPrint, BeforePrint, OneNdPage, OnstartPage, and OnPreView events, these events are relatively simple, and there is not much to use in practical applications, there is no more.

Fourth, the section of the report control is placed

As a report, it usually has a fixed mode, the most common reporting is mainly composed of the following six parts:

PageHeader: Header, each page will appear | Title: Title, only in the first page | ColumnHeader: All columns of the title, the field area of ​​the report file, only once per page | detail: recorded content, one Field, ie, the text area of ​​the report (repeating area) | Summary: Summary (only on the last page) | PageFooter: Foot, each page will appear in QuickReport, is implemented by different TQRBAND sections.

Tqrband is a container on top of the TQUickRep component, we can place the visual QuickReport component we have to print on it. Through the settings for TQRBAND's BANDTYPE attribute, we can change the type of TQRBAND section to achieve functionality of different sections.

BandType is an enumetric variable, apparent that the six parts of the common statement forms in the table will also appear in the enumeration value of the BandType, but the prefix RB is added to each other. We choose different BandType values ​​to represent different section types, implement different features, this must be noted.

In fact, TQRBAN's BandType property value is more than six, and she has the following values:

RBGROUPHEADER: Group page eyebrow table, used in the start of each page in the flag group, also used for TQRSUBDetail;

RBGroupFooter: Group foot table elements, partitioning single page with RBGroupHeader, suitable for TQRGroup and TQRSUBDetail;

Rbsubdetail: Word data table element, no need to manually set;

RBCHilder: Word table CET without manual settings.

In fact, we can also arrange the segment in tquickrep. We will see the six values ​​above the " " in front of the tquickrep component, you will see the six values ​​above (of course, each of the front is added with HAS, Not RB), these values ​​are Boolean, and we want to use which section type TQRBAND, you can set it to True. It can be seen from this point that the former can arrange the BAND segment more flexible, and the latter is more convenient, fast, as for which one you use, then you will see that your mood is in the actual situation. Single from the rigor, it is better to set the section type by tqrband's BandType, and the problem that the report will have the least.

V. Report Operation Components TQREXPR and System Function Components TQRSYSDATA

Reporter Components TQREXPR is used to provide some simple computing functions. The Expression property is her most important attribute, and we must also master her.

Just click Edit button on the EXPRESSITION button to open the expression editing window. With this editor, we can make a more convenient design expressions. By the transformation in the Expression Editor window, you can insert the fields, functions, mathematics, and logical operators of the tables in the database, and can test the correctness of the expression by validate.

Of course, we can also enter expressions directly in the editor.

In her function, if you must use it, because she will help us with a lot of busy, this function should be very familiar with program enthusiasts who have learned DBASE, because they are the same here; C, she is similar to for (;;) statement or "?:" The expression is almost. Her specific use format is as follows: IF (conditional style, in order to use this sentence, for the assumption of this sentence)

System Function Components TQRSYSDATA can provide us with some currently available system features. In order to achieve these features, he provides two important attributes DATA and TEXT.

Data is an enumerated type variable, which has seven values, as follows:

System function type table (DATA Table)

System function type

Function description

QRSTIME

system time

QRSDateTime

System date and time

Qrsdetailcount

Number of records that need to be printed

QRSDetailno

Recording indexing in printing

QRSPAGENUMBER

Page being printed

QrsReportTILE

Report title

QRSDate

System date

The Text attribute is a string type variable to form a complete system function string.

Data and Text These two attributes are usually used together. If you set the text to "Print Time:", the DATA is set to QRSDataTime, and the system print results are "print time: 2003-9-21 13:08:12".

In many cases, we want to print the page number such as "Page 1", using the above properties, which is not implemented, this is to write code to implement. When printing / displaying a report, the application will trigger the onprint event handle. This way we can only write as the following code is written in the onprint of the report arithmetic component TQREXPR or system function component TQRSYSDATA:

Void __fastcall tform1 :: tqrexpr1print (TOBJECT * SENDER, ANSISUSTRING & VALUE)

{

Value = "No. Value " Page ";

}

/ / -------------------------------------------------------------------------------------------- -------------------

or

Void __fastcall tform1 :: tqrsysdata1print (TOBJECT * SENDER, ANSISTRING & VALUE)

{

Value = "No. Value " Page ";

}

/ / -------------------------------------------------------------------------------------------- -------------------

Through these two code we can know that the two components show or work is Value. If we do not modify the value of Value, print the value directly. Since we modified her value in the OnPrint event, the content of printing was changed.

Note: Some friends have entered the above code, but they can't get the correct content. The reason is very simple: TQrsysData's Data property setting is not correct, in this example we have to get the number of pages, see if the value of DATA is QRSPAGENUMBER, and Whether the value of text is empty; for the TQREXPR component, do you enter the next page via the Expression editor's Variable button, select the PAGENUMBER value? This is what you can't correctly have a problem.

Sixth, TQRSHAPE components

The TQRSHAPE component can output some simple graphics on the report, setting up its Shape property, but it is mainly used to draw the table line, so it is somewhat different from Tshape, let's take a look at the value of Shape: TQRShape component Shape attribute values ​​table

Shape attribute value

significance

QRSCIRCLE

Paint

Qrshorline

Draw a horizontal straight line (HEIGHT is set to 1 or other)

QrsRectangle

Draw rectangle

QrsrSrightandLeft

Painted only in the left and right rectangles

Qrstopandbottom

Only in the rectangle

QRSVERTLINE

Painted straight line (Width is set to 1 or other)

As the four position properties of the drawing assembly, they are most important, they are Top, Left, Height, and Width. In fact, these four attributes are also very important for the vast majority of QuickRep.

When the Shape property value is QRShorline / QRSVERTLINE, the attribute value of Height / Width is changed to 1 or other, depending on the width of your line.

The brush property is used to set the fill-in-style inside the geometry, which includes filling color Color and padding pattern style.

The PEN property is used to set the properties of the brush for the drawing, which includes Color, Style, Mode, Wide, etc.

TQRSHAPE components have many of the TSHAPE components, but there are also some differences, and we must pay attention to the value of Shape properties, etc. In fact, through the comparison of two similar components, we will deepen our mastery of them. If you use it, the beautiful line will appear in front of us.

For the use of TQRShape components, more skilled, she should be the best master in all QuickReport components, the usage rate is also one, and the role of TQRShape in the table design is not replaced by other components. However, this article is limited to the space is not explained.

转载请注明原文地址:https://www.9cbs.com/read-7253.html

New Post(0)