⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 4 页
字号:
difficult, but fortunately the QuickReport components make it easy. The best wayfor me to explain how to create reports by hand is to take you through an exercise.This exercise creates a simple application that displays and prints a report in listform. I won't tell you to perform every single step in this exercise. For example,I won't tell you to save the project or give you filenames to use--you can figurethose out for yourself. Also, you don't have to worry about making the report realpretty at this point. You can go back later and tidy up.</P><P>The first step is to create the main form of the application. After that's done,you create the basic outline of the report. Here goes:</P><DL>	<DT></DT>	<DD><B>1. </B>Create a new application. Place two buttons on the main form. Change	the caption of the first button to Preview Report and the caption of the second button	to Print Report.	<P>	<DT></DT>	<DD><B>2. </B>Choose File|New. Double-click the Report icon in the Object Repository.	Delphi creates a new QuickReport form.	<P>	<DT></DT>	<DD><B>3. </B>Place a Table component on the QuickReport form. Change the DatabaseName	property to DBDEMOS and the TableName property to EMPLOYEE.DB. Set the Active property	to True.	<P>	<DT></DT>	<DD><B>4. </B>Select the QuickReport form. Change the DataSet property to Table1	and change the ReportTitle property to Employee Report.	<P>	<DT></DT>	<DD><B>5. </B>Switch back to the main form. Double-click the button labeled Preview	Report. Type this code in the OnClick event handler:	<P></DL><BLOCKQUOTE>	<PRE>QuickReport2.Preview;</PRE></BLOCKQUOTE><PRE></PRE><DL>	<DT></DT>	<DD><B>6. </B>Double-click the Print Report button and type the following in the	OnClick event handler:	<P></DL><BLOCKQUOTE>	<PRE>QuickReport2.Print;</PRE></BLOCKQUOTE><PRE></PRE><DL>	<DT></DT>	<DD><B>7. </B>Choose File|Use Unit and include the QuickReport form.	<P></DL><P>Now you have a blank report. What you need to do next is add a title band, a columnheader band, and a detail band. For the next few steps you might want to look aheadto Figure 18.6 to see the final result. Follow these steps:</P><DL>	<DT></DT>	<DD><B>1. </B>Select a QRBand component from the QReport tab of the Component palette	and place it on the report. The band is a title band by default.	<P>	<DT></DT>	<DD><B>2. </B>Select a QRLabel component and place it on the title band. Change the	Caption property to Employee Report and change the Font property to your preference	(I used Arial, 18 point, bold). Align the component so that it is centered on the	band.	<P>	<DT></DT>	<DD><B>3. </B>Place another band on the report. Change the BandType property to rbColumnHeader	and change the Font to bold and underlined.	<P>	<DT></DT>	<DD><B>4. </B>Place a QRLabel on the left side of the column header band and change	the Caption property to Employee Number. Place a second QRLabel on the band to the	right of the first and change the Caption property to Name. Place a third QRLabel	on the band to the right of the last label and change the Caption to Salary.	<P>	<DT></DT>	<DD><B>5. </B>Place another band on the report and change the BandType property to	rbDetail. Notice that the band moves below the other bands after you change the band	type.	<P>	<DT></DT>	<DD><B>6. </B>Place a QRDBText component on the left edge of the detail band (align	it with the Employee Number label on the column header band). Change the DataSet	property to Table1 and the DataField property to EmpNo.	<P>	<DT></DT>	<DD><B>7. </B>Place another QRDBText on the detail band and align it with the Name	component on the column header band. Change the DataSet property to Table1 and the	DataField property to FirstName. Place another QRDBText just to the right of the	last one (see Figure 18.6). Attach it to the LastName field of the database table.	<P></DL><PRE><B>	8.	</B>Add a final QRDBText component on the detail band. Place it below the Salary component on the column header band and attach it to the Salary field in the table. Your form now looks like Figure 18.6. </PRE><P><A HREF="javascript:popUp('28671806.gif')"><B>FIGURE 18.6.</B></A><B> </B><I>YourQuickReport form.</I></P><P>You are probably wondering what the report will look like on paper. Guess what?You don't have to wait to find out. Just right-click on the QuickReport form andchoose Preview from the context menu. The QuickReport preview window is displayed,and you can preview the report.</P><P>To print the report, click the Print button. When you are done with the reportpreview, click the Close button. You can now run the program and try out the PreviewReport and Print Report buttons.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> The report you just created is double-spaced. To change the spacing,	reduce the height of the detail band. <HR></BLOCKQUOTE><P>Before leaving this discussion of reports, let me show you one other nice featureof QuickReport. Right-click on the QuickReport form and choose Report settings fromthe context menu. The Report Settings dialog will be displayed, as shown in Figure18.7. This dialog enables you to set the primary properties of the QuickRep componentvisually rather than use the Object Inspector.</P><P><A HREF="javascript:popUp('28671807.gif')"><B>FIGURE 18.7.</B></A><B> </B><I>TheQuickReport Report Settings dialog.</I></P><H3><A NAME="Heading14"></A>Creating Reports the Easy Way</H3><P>Delphi comes with three built-in QuickReport forms, which can be found on theForms tab of the Object Repository. The forms are called Quick Report Labels, QuickReport List, and Quick Report Master/Detail. These forms give you a head start oncreating reports. You can generate one of the forms from the Object Repository andthen modify the form as needed.</P><P><H2><A NAME="Heading15"></A>Deploying a Delphi Database Application</H2><P>As I said on Day 16, the Borland Database Engine (BDE) is a collection of DLLsand drivers that enable your Delphi application to talk to various types of databases.When you ship an application that uses the BDE, you need to make sure that you shipthe proper BDE files and that they are properly registered on your users' machines.</P><P>The most sensible way to do this is with a Borland-approved installation program.Here at TurboPower Software, we use the Wise Install System from Great Lakes BusinessSolutions (<A target="_new" HREF="http://www.glbs.com">http://www.glbs.com</A>). Others includeInstallShield and its little brother, InstallShield Express. Conveniently, InstallShieldExpress comes with Delphi Professional and Client/Server, so if you have one of thoseversions of Delphi, you don't have to rush right out and buy an installation program.</P><P>You might be wondering why Borland is involved in dictating how the BDE must bedeployed. The reason is simple when you think about it: There are many BDE versionsin use. Some folks might be writing and deploying applications that use the BDE fromDelphi 1. Others might be using the BDE from C++Builder 1. Still others could beusing the BDE that comes with Delphi 4 in their applications.</P><P>The important point to realize is that the BDE is backward compatible. Newer BDEversions are guaranteed to work with applications written for older BDE versions.This system will only work, however, as long as everyone plays by the rules. Partof the rules say, &quot;Thou shalt not arbitrarily overwrite existing BDE files.&quot;Certified installation programs check the version number of any BDE files they find.If the file being installed is older than the existing file, the installation programleaves the existing file in place.</P><P>This ensures that the user will always have the latest BDE files on his or hersystem. Another service that these certified installation programs provide is todetermine exactly which files you need to deploy for your application. You shouldread DEPLOY.TXT in the Delphi root directory for more details on deploying applicationsthat use the BDE.</P><P><H2><A NAME="Heading16"></A>Summary</H2><P>There's no question that creating database applications requires a lot of work.The good news is that Delphi makes the job much easier than other development environments.Today you found out something about the nonvisual aspects of database programming.You also found out about data modules and how to use them. You ended the day witha look at QuickReport. QuickReport makes creating reports for your database applicationseasy. I also explained what is required to deploy a database application.</P><P><H2>Workshop</H2><P>The Workshop contains quiz questions to help you solidify your understanding ofthe material covered and exercises to provide you with experience in using what youhave learned. You can find answers to the quiz questions in Appendix A, &quot;Answersto the Quiz Questions.&quot;</P><P><H3><A NAME="Heading17"></A>Q&amp;A</H3><DL>	<DT></DT>	<DD><B>Q I am trying to create a database at runtime. I have created a BDE alias	and set all the field definitions, but the table is never created on my hard disk.	What have I done wrong?</B>	<P>	<DT></DT>	<DD><B>A </B>You have probably failed to call the CreateTable method. You must call	this method to physically create the table.	<P>	<DT></DT>	<DD><B>Q When designing a report, can I set all my report's properties at one time?</B>	<P>	<DT></DT>	<DD><B>A </B>Yes. Just right-click the QuickRep component and choose Report settings	from the context menu. The Report Settings dialog is displayed, and you can set most	of the report properties visually.	<P>	<DT></DT>	<DD><B>Q Can a data module include code as well as components?</B>	<P>	<DT></DT>	<DD><B>A </B>Yes. A data module can contain any code necessary to carry out operation	of the data module. The data module can contain event handlers or methods that you	create. The methods you create can be public or private (for the data module's use	only).	<P>	<DT></DT>	<DD><B>Q When I preview my report, it is blank. What is wrong?</B>	<P>	<DT></DT>	<DD><B>A </B>More than likely you have not set the Active property of the dataset	to True. The dataset must be open before the report will function.	<P>	<DT></DT>	<DD><B>Q Can I use more than one detail band on a report?</B>	<P>	<DT></DT>	<DD><B>A </B>No. You can place more than one detail band on a report, but only the	first one will be used when the report is generated.	<P>	<DT></DT>	<DD><B>Q Why do I need a Borland-approved installation program to install my database	application?</B>	<P>	<DT></DT>	<DD><B>A</B> The BDE is complicated to install, and an approved installation program	is guaranteed to do the installation correctly.	<P></DL><H3><A NAME="Heading18"></A>Quiz</H3><DL>	<DD><B>1. </B>What method do you call to create a database table at runtime?	<DT></DT>	<DD><B>2. </B>What does the Edit method of TTable do?	<P>	<DT></DT>	<DD><B>3. </B>What method do you call when you want to apply the changes made to	a record?	<P>	<DT></DT>	<DD><B>4. </B>How do you create a new data module?	<P>	<DT></DT>	<DD><B>5. </B>Is a data module a regular form?	<P>	<DT></DT>	<DD><B>6. </B>What method do you call to print a QuickReport?	<P>	<DT></DT>	<DD><B>7. </B>What type of QuickReport band displays the dataset's data?	<P>	<DT></DT>	<DD><B>8. </B>What component is used to display the page number on a report?	<P>	<DT></DT>	<DD><B>9. </B>How can you preview a report at design time?	<P>	<DT></DT>	<DD><B>10. </B>What is the QRExpr component used for?	<P></DL><H3><A NAME="Heading19"></A>Exercises</H3><DL>	<DT></DT>	<DD><B>1. </B>Create a database (a BDE alias) and a table for the database, either	through code or by using the Delphi database tools.	<P>	<DD><B>2. </B>Create a data module containing the database table from exercise 1.	<DT></DT>	<DD><B>3. </B>Generate a report that creates mailing labels. (Hint: Start with a	QuickReport Labels object from the Forms page of the Object Repository.)	<P>	<DT></DT>	<DD><B>4. </B>Modify the QuickReport you created in this chapter so that the employee's	first and last names are displayed by a QRExpr component.	<P>	<DT></DT>	<DD><B>5. </B>Read the DEPLOY.TXT file in your Delphi directory to understand what	is involved in deploying a Delphi database application.</DL><H1></H1><CENTER><P><HR><A HREF="../ch17/ch17.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch19/ch19.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR></P><P>&#169; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -