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

📄 ch17.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 4 页
字号:
differences between a list box and a combo box.</P><P><H3><A NAME="Heading15"></A>The DBCheckBox Component</H3><P>You use the DBCheckBox primarily to display the contents of a database field containinglogical data (True/False, Yes/No, On/Off). Set the ValueChecked property to a stringthat should be used to check for a match against the contents of the field. For example:</P><P><CENTER><H1>DBCheckBox1.ValueChecked := `On';</H1></CENTER><P>In this case, if the associated field contains the value On, the DBCheckBox willbe checked. If the field contains a value other than the one specified, the checkbox will not be checked. You can supply more than one value to check in the ValueCheckedproperty. For example:</P><P><PRE>DBCheckBox1.ValueChecked := `On;Yes;True';</PRE><P>If the value of the associated field contains any one of these values, the checkbox will be checked. The ValueUnchecked property works in exactly the same way exceptthat any values matching the contents of ValueUnchecked will cause the check boxto be cleared (unchecked). When specifying values for both ValueChecked and ValueUnchecked,the check box state will be indeterminate (grayed check mark) for field values thatdon't match.</P><P><H3><A NAME="Heading16"></A>The DBRadioGroup Component</H3><P>The DBRadioGroup component works much like the DBListBox and DBComboBox components.You supply the items for the radio group and when an item is selected, the value(text) associated with that radio button is written to the associated field in thedatabase.</P><P>The Values property holds the current value of the field in the database. Youcan use the Values property to substitute the display string in the radio group boxwith a different string. For example, you might have a radio group box with radiobuttons labeled Yearly, Quarterly, and Monthly. Your database, however, might storecodes such as Y, Q, and M instead of the full names. Given that scenario, you couldset the Values property (a string list) like so:</P><P><PRE>YQM</PRE><P>Now, when a radio button is selected, the one-letter code will be written to thedatabase field instead of the display string of the selected radio button. If theValues property is empty, the display string of the radio button will be writtento the database when a radio button is clicked.</P><P><H3><A NAME="Heading17"></A>The DBLookupListBox and DBLookupComboBox Components</H3><P>The DBLookupListBox component enables you to display a list of field values froma lookup field. Unlike the DBComboBox component, the list isn't provided by you;it is provided by a separate dataset. Set the DataSource and DataField propertiesto the dataset and field where the selection will be written. Set the ListSourceand ListField properties to the lookup field from which the list should be populated.</P><P>The DBLookupComboBox works just like the DBLookupListBox. In addition, the DropDownAlign,DropDownRows, and DropDownWidth properties control how the drop-down list appears.</P><P><H3><A NAME="Heading18"></A>The DBRichEdit Component</H3><P>The DBRichEdit component enables you to display and edit a rich text memo fieldin a dataset. The AutoDisplay property and LoadMemo methods of this component workexactly as they do for the DBMemo component.</P><P><H3><A NAME="Heading19"></A>The DBCtrlGrid Component</H3><P>DBCtrlGrid is a component that enables you to create custom scrollable grid components.You can place any data components you want on the first cell of the DBCtrlGrid (orany other components for that matter), and Delphi will duplicate those componentsfor each record in the dataset.</P><P>An illustration helps this explanation make more sense. Figure 17.12 shows a formcontaining a DBCtrlGrid component that has been aligned so that it fills the form'sclient area. The DBCtrlGrid contains a DBEdit, a DBMemo, and a DBImage. All the datacomponents are placed on the first cell of the grid. The second cell contains a hatchpattern to tell you that you can't place components on that cell. Figure 17.13 showsthe same form when the application is running.</P><P><A HREF="javascript:popUp('28671712.gif')"><B>FIGURE 17.12.</B></A><B> </B><I>Aform at design time containing a DBCtrlGrid component.</I></P><P><A HREF="javascript:popUp('28671713.gif')"><B>FIGURE 17.13.</B></A><B> </B><I>Thesame form at runtime.</I></P><P>The DBCtrlGrid has a few properties worth mentioning. You use the Orientationproperty to determine where the scrollbar is to be placed and how the component actswhen the scrollbar is clicked (the DBCtrlGrid in Figures 17.12 and 17.13 has theOrientation set to goHorizontal). You use the PanelWidth and PanelHeight propertiesto set the width and height of a cell in the grid. The RowCount property determineshow many records to show at one time.</P><P>The DBCtrlGrid component has one event, OnPaintPanel. This event is fired eachtime a grid cell needs painting. You can respond to this event in order to draw onthe background of the panel. This pertains only to the panel's background. Any controlson the grid will be painted automatically, so you don't have to worry about them.</P><P><H3><A NAME="Heading20"></A>Other Data Components</H3><P>DBChart is a charting component included with the Professional and Client/Serverversions of Delphi. This component is not only powerful, but also complex. I can'tbegin to explain everything the DBChart component does, so you'll have to experimentwith it to discover all that it is capable of.</P><P>The Client/Server version of Delphi includes a tab named Decision Cube that containssix additional components. These components enable you to do complex data analysissuch as cross tabulation of tables and graphs, drill down, pivot, and aggregation.A discussion of these components wouldn't be productive here, but I want you to beaware that these components exist in the Client/Server version of Delphi.</P><P><H2><A NAME="Heading21"></A>Summary</H2><P>Well, that about sums up the art of building database forms. (Actually, I'm beingfacetious because I've just scratched the surface of database form creation and design.)Use the Database Form Wizard for quick and easy database forms. Create database formsfrom scratch for more flexibility. Either way you go, building good database formstakes time and experience to master. It isn't something that you can be great atovernight. On the other hand, it isn't terribly difficult, either. Keep working atit and you'll be a database whiz in no time. The important thing is knowing the datacomponents available to you as you build your forms.</P><P><H2><A NAME="Heading22"></A>Workshop</H2><P>The Workshop contains quiz questions to help you solidify your understanding ofthe material covered and exercises to provide you with experience using what youhave learned. You can find the answers to the quiz questions in Appendix A, &quot;Answersto the Quiz Questions.&quot;</P><P><H3><A NAME="Heading23"></A>Q&amp;A</H3><DL>	<DT></DT>	<DD><B>Q I like the way the Database Form Wizard saves me time, but I don't like	the way the components are arranged on the form. What do you suggest?</B>	<P>	<DT><B></B></DT>	<DD><B>A </B>Run the Database Form Wizard to create components for any fields you	want on your form. Then manually rearrange the components to make the form look the	way you want. The Database Form Wizard just gives you a head start. You can do anything	you want with the form after the Database Form Wizard has done its job.	<P>	<DT></DT>	<DD><B>Q When using the Database Form Wizard, does it matter whether I create a form	using TTable or TQuery objects?</B>	<P>	<DT><B></B></DT>	<DD><B>A </B>It all depends on the type of database you are talking to. If you are	dealing with a local database such as Paradox or dBASE, you will probably use a TTable.	If you are dealing with a client/server database, you will likely use a TQuery.	<P>	<DT></DT>	<DD><B>Q Is there any limit to the number of DataSource, Table, and Query components	I can have on my form?</B>	<P>	<DT><B></B></DT>	<DD><B>A </B>There's no absolute limit, although there are practical limits to how	many datasets you can work with at one time.	<P>	<DT></DT>	<DD><B>Q I noticed the DBEdit component doesn't have a Text property like the regular	Edit component has. Why is that?</B>	<P>	<DT><B></B></DT>	<DD><B>A </B>The DBEdit component doesn't have a Text property because the component	contents are obtained from a dataset. To access the contents of a DBEdit component,	use the dataset's GetFieldByName method and the Value property of TField.	<P>	<DT></DT>	<DD><B>Q Do I have to use a DBNavigator to enable my users to browse the database?</B>	<P>	<DT><B></B></DT>	<DD><B>A </B>No, you could provide your own buttons and then write code to move the	database cursor when the buttons are clicked. Using a DBNavigator is much easier,	though.	<P></DL><PRE><B>	Q	My database contains a number of large images in BLOB fields, and it seems to take a long time to display the images. Is there something I can do to make the images draw faster?</B></PRE><DL>	<DT></DT>	<DD><B>A </B>Make certain that you have the QuickDraw property set to True. Your	images will draw faster, but they might not look as good.	<P></DL><H3><A NAME="Heading24"></A>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>What's the fastest and easiest way to create a database form?	<P>	<DT></DT>	<DD><B>2. </B>How do you control the order and number of columns that appear in a	DBGrid component?	<P>	<DT></DT>	<DD><B>3. </B>What component enables you to display a dataset in table format?	<P>	<DT></DT>	<DD><B>4. </B>How can you add or remove buttons from a DBNavigator?	<P>	<DT></DT>	<DD><B>5. </B>What component do you use to display BLOB image data?	<P>	<DT></DT>	<DD><B>6. </B>What property is common to all data-aware components?	<P>	<DT></DT>	<DD><B>7. </B>What property is used to select the field that a data component is	linked to?	<P>	<DT></DT>	<DD><B>8. </B>Can you rearrange the columns in a DBGrid component?	<P>	<DT></DT>	<DD><B>9. </B>Which component is used to edit and display text fields in a database?	<P>	<DT></DT>	<DD><B>10. </B>What does BLOB stand for?	<P></DL><H3><A NAME="Heading25"></A>Exercises</H3><DL>	<DT></DT>	<DD><B>1. </B>Create a new application that shows the contents of the VENDORS.DB	table (DBDEMOS database).	<P>	<DT></DT>	<DD><B>2. </B>Modify the application in step 1 so that only the VendorName, City,	State, and Phone fields are displayed.	<P>	<DT></DT>	<DD><B>3. </B>Delphi Professional and Client/Server owners: Create a master/detail	form from the IBLOCAL database (install Local InterBase from the Delphi CD if necessary).	Use the EMPLOYEE table as the master and the EMPLOYEE_PROJECT table as the detail	table. (Hint: Use the EMP_NO field to link the tables.)	<P>	<DT></DT>	<DD><B>4. </B>Create a database form that uses a DBCtrlGrid component to browse a	table. Use any table and include any fields you like.	<P>	<DT></DT>	<DD><B>5. </B>Create a database form by hand (not using the Database Form Wizard)	using any table and any fields you like. Add a DBNavigator component to browse the	table.	<P>	<DT></DT>	<DD><B>6. </B>Remove all buttons from the DBNavigator used in step 5 except the First,	Next, Prior, and Last buttons.</DL><H1></H1><CENTER><P><HR><A HREF="../ch16/ch16.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch18/ch18.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><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 + -