1. 建立一个新project。
2. 放一个Tquery在Tquickrep上,其SQL属性为:select * from customer order by State,Company;(即根据州、公司排序),
DatabaseName为BCDMome,Active为true.
3. 放一个TquickRep控件在Form1上,DataSet为Tquery1.
4. 放一个TQRGroups控件在TquickRep上,这时默认为group header。
(任何时候当group中断或更高级别的group中断,这个header都将打印出来,如果有表达式,根据表达式的值显示内容。)
接着添加一个group footer band,添加时,放一个TQRBand控件在报表上,连接TQRGroups的FooterBand属性到这个QRBand,
这时这个新建的TQRBand就成为Group Footer. (TQRGroup的一个重要特性是表达式,任何时候当表达式的值变时Group都将中断,
如表达式是按省列出城市名,当前列出广东省,当属于该省的城市列完后,表达式值改变,这时Group中断,接着显示其他省的城市名。)
TQRGroups的Expression属性设为Query1.State(根据不同的州来中断)。
5. 放一个TQRBand控件在报表上,BandType为rbDetail.
6.放一个TQRExpr控件在group header上面,其Expression属性为:if(State<>’’,State,’Unknown state’),
即如果公司的州没填,就归入Unknown state,否则归入State.
7.放三个TQRDBText在Detail上,他们的DataSet都指向Query1,DataField分别指向Company,Contact,Phone.
8.在放一个TQRExpr控件在group Footer上面,Expression为’Customers in’+State+’:’+Str(Count)
作用是在每个州的公司列完后显示该州总共有多少个公司。
9.按右键选预览,应该看到不同的州名及其公司和公司公司总数。
按多个条件分组时在Expression使用"+"号
每页进行统计时在Expression选择函数sum,count等,如果分页后把统计设为0设置属性resetafterprint为true
当没有数据的时候是否打印页头等数据可设置PrintIfEmpty来控制,如果为true,没数据也打印页头,为false,没数据就不打印了。
如果想按分组来分页打印,可设置属性ForceNewPage为true
如果想取的总页数,可先调用 QuickRep1.Prepare 来执行准备工作,再调用QuickRep1.QRPrinter.PageCount来获得总页数,
为了内存安全,一般使用方法如下:
QuickRep1.Prepare;
try
QRLabel2.Caption := inttostr(QuickRep1.QRPrinter.PageCount);
finally
QuickRep1.QRPrinter.Free;
end;
QuickRep1.QRPrinter := nil;
在打印前如果想弹出设置打印机的对话框,可调用方法:QuickRep1.printersetup;
预览方法:QuickRep1.Preview;
打印方法:QuickRep1.Print;
打印前准备方法:QuickRep1.Prepare ;
设置横向打印:QuickRep1.page.orientation := poLandscape
设置纵向打印:QuickRep1.page.orientation := poPortrait
设置纸张类型:QuickRep1.page.pagersize := A4
Converts a string to a numeric representation.
Unit
System
Category
string handling routines
procedure Val(S; var V; var Code: Integer);
Description
Val converts the string value S to its numeric representation, as if it were read from a text file with Read.
S is a string-type expression; it must be a sequence of characters that form a signed real number.
V is an integer-type or real-type variable. If V is an integer-type variable, S must form a whole number.
Code is a variable of type Integer.
If the string is invalid, the index of the offending character is stored in Code; otherwise, Code is set to zero. For a null-terminated string, the error position returned in Code is one larger than the actual zero-based index of the character in error.
Val performs range checking differently depending upon the setting of the $R compiler directive and the type of the parameter V.
Setting Result
{$R+} An out-of-range value always generates a run-time error.
{$R-} The values for out-of-range vary depending upon the data type of V.
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | Current | > >> | ||||
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 | |||||