Teach Yourself Borland Delphi 4 in 21 Days

Previous chapterNext chapterContents


- 17 -

Building Database Forms


After a relatively unexciting look at Delphi database architecture, you can move on to the more interesting task of building a database application. The first step in that task is to learn how to create database forms, so that's today's subject.

You'll learn how to create database forms using the Delphi Database Form Wizard. You'll also learn how to build database forms from scratch. Toward the end of the day, you will learn about the data components of Delphi. These are the components that display the data from a database and enable you to edit that data--you can find them on the Data Controls tab of the Component palette. They are often referred to as data-aware components. I'll just call them data components in this chapter. Let's get to it.

The Database Form Wizard

The Delphi Database Form Wizard provides a way of creating database forms quickly and easily. Using this wizard, you can create a database form from start to finish. You don't have to place any database components on the form. You just start the wizard and let the wizard take it from there.


NOTE: No automated process is good enough to be all things to all people. I won't pretend that the forms created by the Database Form Wizard will be everything you want or that the Database Form Wizard will do all your work for you. What the Database Form Wizard can do, though, is the initial work of setting up a database form. After the initial work is done, you can go to work customizing the form to make it look the way you want.

The Database Form Wizard enables you to create both simple forms and master/detail forms. It enables you to choose whether your dataset will be a TTable or a TQuery. The wizard enables you to select a database table and to select the fields from that table that you want displayed on the form. It gives you a choice of layout options as well. After you supply the Database Form Wizard with all the information it needs, it creates the new form for you.

To start the Database Form Wizard, choose Database | Form Wizard... from the Delphi main menu. Alternatively, you can start the Database Form Wizard from the Business page of the Object Repository.

First I'll show you how to create a simple form, and then I'll talk about master/detail forms.

Creating a Simple Form Using the Database Form Wizard

When the Database Form Wizard starts, it displays the page shown in Figure 17.1.

FIGURE 17.1. Page one of the Database Form Wizard.

This page of the Database Form Wizard asks you to choose the type of database you want to create and the dataset type you would like to use. The Form Options section gives you the choice of creating a simple form (with a single dataset) or a master/detail form.

I talked briefly about master/detail tables yesterday in the section "Master/Detail Tables." I'll talk more about master/detail forms later today in the section "Creating a Master/Detail Form." The first page of the Database Form Wizard also enables you to select from either a TTable-based dataset or a TQuery-based dataset. For this exercise, the default settings for creating a simple form using a TTable dataset are what you want, so you can click the Next button to move on to the next page.


TIP: In some cases, you might want to implement data from more than one table on a single form but not use a master/detail relationship. The Database Form Wizard enables you to choose only from one table. What you can do, though, is run the Database Form Wizard and select the first table. Your form will be created. Change the names of the Table and DataSource components to something meaningful. Now run the Database Form Wizard again and choose the second table. When the form is displayed, select all the database components on the form and copy them to the Clipboard. Switch back to the first form, make some room on the form for the new components, and paste them from the Clipboard onto the form. Now remove the second form from the project, and you're all set.

The next page asks you to choose a table from which to obtain the data. The Drive or Alias name combo box enables you to choose a database name just as you do when setting the DatabaseName property for a dataset component at design time. It also enables you to choose a directory from which to select a table. For this example, choose the DBDEMOS alias. The tables available in the database will show up in the Table Name list box. Select the ANIMALS.DBF table. The Database Form Wizard now looks like the one in Figure 17.2. Click the Next button to go to the next page.

FIGURE 17.2. Selecting a table with the Database Form Wizard.

The third page of the Database Form Wizard asks you to choose the fields from the table that you want to include on the form. The Available Fields list box on the left shows the fields that are in the table you have selected. The Ordered Selected Fields list box on the right contains the fields that you want on your new form. Between the two list boxes are four buttons for adding or removing fields from the Ordered Selected Fields list box.

To add a field, click the field name in the Available Fields list box and click the > button. Add any fields you want with this method. You can select multiple fields and click the > button to add the selected fields. To add all fields in the table at one time, click the >> button.


TIP: You can double-click a field name to add that field to the Ordered Selected Fields list box or double-click it again to remove it from the list box.

After the fields have been added to the Ordered Selected Fields list box, you can change the order of the fields by drag and drop or by clicking the up and down arrow buttons below the list box. Figure 17.3 shows this page of the wizard. For now, add all the fields to the Ordered Selected Fields list box and click the Next button to move to the next page.

FIGURE 17.3. Page three of the Database Form Wizard, adding fields.

The next page of the Database Form Wizard dialog asks you how you want the components for each field arranged on the form. You have three layout choices:

Click each of the three radio buttons and watch the image to the left of the wizard as you select different options. The image changes to show you the layout for each choice. Select the radio button labeled Vertically and click the Next button to continue. Figure 17.4 shows this page of the wizard.

FIGURE 17.4. Selecting a layout style with the Database Form Wizard.



NOTE: When Delphi creates the database form, it chooses the component type that most closely matches the data type of the field that component represents. For example, a regular text field is represented by a DBEdit component, a memo field by a DBMemo component, and a BLOB image field by a DBImage component. Delphi makes a best guess as to the component type to place on the form for a given data type. You might have to edit the form to get exactly the component you want for a given field.

The next page asks where you want to place the labels for the fields relative to each data component. You can put the labels on top of the components or to the left. Notice that here, too, the image on the Database Form Wizard changes depending on which of the two options is currently selected. For now, choose the second option in order to place the labels on top of the components. Figure 17.5 shows this page of the Database Form Wizard.

FIGURE 17.5. This page enables you to place the labels.


NOTE: The page shown in Figure 17.5 appears only if you select the option for vertical component layout on the previous page of the Database Form Wizard.

The final page of the Database Form Wizard asks you to make two choices:


NOTE: If you choose to have Delphi create the new database form as the main form of the application, be aware that the existing main form will still be part of the application's project. You need to remove the old main form from the project if you don't want it anymore. To remove the old main form, click the Remove from Project button and remove the main form's unit (Unit1.pas for a default project).

I'll talk more about data modules tomorrow in the section "Working with Data Modules." For now, make certain that the Generate a Main Form check box is checked and that the Form Generation option is set to Form Only. Figure 17.6 shows the last page of the Database Form Wizard.

FIGURE 17.6. The last page of the Database Form Wizard.

Click the Finish button and the form will be created. The finished form looks like the one shown in Figure 17.7.

FIGURE 17.7. The finished form.

Notice in Figure 17.7 that the form contains a data component for each field that was selected and a label for each component. The label is capitalized because that's the way the field names are stored in this particular table. Notice that the top of the form contains a DBNavigator component so that you can browse the records of the table.

The New Form in Action

Now you are ready to click the Run button and see how the form works. When the application starts, the first record in the dataset is displayed. Use the buttons of the DBNavigator to move through the dataset. Keep in mind that you are working with live data at this point. You can edit a record by changing a value in one of the edit components. To save the changes to the database, click the Post button on the DBNavigator (the check mark). To cancel any changes to the record, click the Cancel button on the DBNavigator (the X button). When you post a record or move to another record, the changes are saved to the database.

Close the application and return to the Delphi IDE. Spend some time examining the components on the form and the components' properties. Later I am going to go over some of the data components, but for now just experiment a little.


NOTE: If you find yourself re-creating a database form over and over again, consider adding the form to the Object Repository. Forms in the Object Repository can be reused with just a few mouse clicks.

Creating a Master/Detail Form

Next, you create a master/detail form using the Database Form Wizard. When creating a master/detail form, the first few pages of the wizard are nearly the same as when creating a simple form. Only the labels that describe your options are different. First, perform the following steps. After that, I explain the specifics of the Database Form Wizard that pertain to master/detail forms. Here goes:

1. Start the Database Form Wizard. On the first page, choose the option to create a master/detail form and the option to use TTable for the dataset components. Click the Next button.

2. The next step is to choose the table that will serve as the master. Select the DBDEMOS alias and then select the CUSTOMER.DB table. Click the Next button.

3. Select just the CustNo and Company fields and add them to the Ordered Selected Fields list box. Click the Next button.

4. Click on the Horizontally option to lay out the components horizontally. Click the Next button.

5. Now choose the table that will provide the details. Select the ORDERS.DB table and then click the Next button.

6. Select the CustNo, OrderNo, SaleDate, and AmountPaid fields and add them to the Ordered Selected Fields list box. Click the Next button.

7. Choose the option to arrange the components in a grid and click the Next button.

Now you are presented with a page you haven't seen before in the Database Form Wizard. This page asks you to select the fields that will join the two tables:

1. Click on the Available Indexes combo box at the top of the page and choose the CustNo field. The CustNo field is designated as a secondary index, so you'll use that field to join the two tables.

2. Select CustNo in both the Detail Fields list box and in the Master Fields list box. After you select CustNo in both list boxes, the Add button between the two list boxes is enabled.

3. Click the Add button to add the join to the Joined Fields list box at the bottom of the page.


NOTE: If you are paying attention, you might notice that this page of the Database Form Wizard looks almost identical to the Field Link Designer you saw on Day 16, "Delphi Database Architecture," when you set up a master/detail form by hand. Both perform the same task.

Figure 17.8 shows the Database Form Wizard after joining the two tables.

FIGURE 17.8. The two tables joined on the CustNo field.


NOTE: The page illustrated in Figure 17.8 is slightly different if you are using TQuery--instead of TTable--components for the datasets. Specifically, the Available Indexes combo box isn't present when using TQuery components. The reason this combo box isn't displayed when using TQuery components is that the join is created using SQL statements, and indexes are not used in the same way they are with TTable components.
4. Click the Next button to move to the next page of the Database Form Wizard. Because this page already has the settings you need, just click the Finish button.

Now Delphi creates the form, and you are ready to try your new creation. Click the Run button to run the program. Use the DBNavigator to move from record to record. You will notice that the customer name is displayed in the top part of the form and that all the orders for that customer are displayed in the table in the bottom part of the form. Figure 17.9 shows the master/detail application running.

FIGURE 17.9. Your new master/detail form in action.


TIP: If you want to see the SQL statements for a master/detail relationship, run the Database Form Wizard again, but this time choose TQuery components for the datasets. After the form has been created, click on each Query component and examine its SQL property.

Creating Database Forms by Hand

The Database Form Wizard is a good tool for quickly laying out a form; it is particularly convenient for quick test programs. It will not be long, though, before you will need to custom-design your database forms. After you gain experience creating database forms, you might actually prefer to create your forms by hand rather than use the Database Form Wizard.

There isn't a lot to know about creating database forms by hand. You drop one or more datasets (Tables or Queries) on the form and a DataSource component for each dataset, and then place a component on the form for each field in the dataset that you want to view. Sounds easy enough, and it is.

Let's build a new form that approximates the form you created earlier in the section "Creating a Simple Form Using the Database Form Wizard." First, you lay the groundwork and start adding the data components. Perform these steps:

1. Start a new application. Place a Panel component on the form and set its Align property to alTop. Remove the caption.

2. Place a ScrollBox component on the form below the panel (you can find it on the Additional tab on the Component palette). Set the Align property to alClient.

3. Place a Table component on the form. You can place it anywhere you like, but the right side of the panel is probably the best place. Change the DatabaseName property to DBDEMOS and the TableName property to ANIMALS.DBF.

4. Place a DataSource component on the form next to the Table component. Change the DataSet property to Table1.

5. Place a DBNavigator on the panel at the top of the form. Change its DataSource property to DataSource1.


TIP: You can set the DataSource property quickly by double-clicking the value column next to the property in the Object Inspector. Delphi will cycle through the available DataSource components each time you double-click.

Your form now looks like Figure 17.10.

FIGURE 17.10. The form in the initial stages.

Now you need to add some data components to display the table's data. As you work through this exercise, you might want to refer to Figure 17.7 to see the result. Do the following:

1. Place a DBEdit component on the main part of the form along the left side. Change the Name property to NameEdit; change the DataSource property to DataSource1; change the DataField property to NAME (choose NAME from the drop-down list).

2. Place a Label component above the DBEdit you created in step 1 (use a regular Label component from the Standard page of the Component palette, not a DBText component). Change its Caption property to Name.

3. Repeat steps 1 and 2 and add DBEdits and Labels for the SIZE, WEIGHT, and AREA fields of the table. Make certain that you change the Name property and DataField property with respect to each field's name.

In the next two steps, you depart from Figure 17.7 and place the component for the BMP field to the right of the components you just placed. It makes more sense for it to be there rather than below the existing components.

4. Place a DBImage component on the form to the right of the edit components. Change the Name property to BMPImage, and change the DataSource property to DataSource1 and the DataField property to BMP.

5. Place a Label component above the DBImage and change its Caption property to Picture (the field name is BMP, but the word Picture is more descriptive).

Now your form looks like the one shown in Figure 17.11.

FIGURE 17.11. The form with the data components in place.

Now you need to set the size of the DBImage component. Although you can't always be sure that each image will be the same size in every database, you can be certain in this case. You might guess at the size of the bitmap, but a better solution would be to set the size with a live image in the component. That's easy enough to fix. Click on the Table component and set its Active property to True. The image for the first record in the table is displayed. Now you can size the DBImage as needed to match the bitmap size.

You have nearly completed the form, but there's one more thing you should do. To imitate the form that the Database Form Wizard created, you need to open the table when the form is created:

1. First, set the Active property of the Table to False (you just set it to True a minute ago).

2. Now select the form itself in the Object Inspector. (Remember that to select the form, you click on the panel and then press the Esc key on your keyboard. You can also select the form from the Component Selector at the top of the Object Inspector.)

3. Switch to the Events page and create an event handler for the OnCreate event. Type this line of code in the event handler:

Table1.Open;

That's it. Your new form is finished. Click the Run button to test your new creation. It will behave exactly like the first form you created with the Database Form Wizard.

A Closer Look at the Data Components

At this point, a quick look at the data components is in order. I'll give a brief overview of each component and highlight each one's key properties and methods. Most of the data components are derived from a standard component and have many of the properties associated with that type of component. I will discuss only the properties that are specific to the data version of each component.

Properties Common to Data Components

All the data components have properties in common. For example, all the components have a DataSource property. This property is used to link a data component with a data source, which is itself linked to a dataset. You have been using the DataSource property a lot in the past couple of days, so you should have a good idea of how it works.

Most data components also have a DataField property. You use this property to hook the data component to a particular field in the dataset. You saw how the DataField property is used when you built a database form from scratch. When you hook a data component to a field in the dataset, the contents of that field are directly displayed in the data component. In the case of Tables (and Queries if the RequestLive property is True), this means that editing the data in the data control will result in changes to the data in the database.

Most data components also have a Field property. You use the Field property to gain access to a component's contents programmatically. For example, to change the contents of a DBEdit component, you can do the following:

NameEdit.Field.AsString := `Clown Fish';

You can also change the field's display characteristics or other TField properties through the Field property.

You can use the ReadOnly property to prevent the user from editing the data in a data component that enables editing (DBGrid and DBEdit, for example).

The DBGrid Component

The DBGrid component displays a dataset in tabular, or spreadsheet, format. One of the most important properties of the DBGrid is the Columns property. This property enables you to change the number and order of the columns that appear in the grid. You can add, remove, and order columns using the Columns Editor.

To invoke the Columns Editor, right-click on the grid and choose Columns Editor from the context menu. You can also click the ellipsis button next to the Columns property in the Object Inspector. Using the Columns Editor, you can add columns, remove columns, and arrange the order of columns. For example, a dataset might contain a dozen fields, but you might want to view only half those fields in the DBGrid. Using the Columns Editor, you can hide the fields that you don't want to see.


NOTE: Don't confuse the DBGrid Columns property (modified with the Columns Editor) with the Table component's FieldDefs property (modified with the Fields Editor). The FieldDefs property of the Table component controls which columns are actually contained in the dataset. The Columns property only affects which fields are visible in the grid.

The DefaultDrawing property indicates whether VCL draws the cells in the grid or the grid cells are owner-drawn. If DefaultDrawing is False, you must respond to the OnDrawColumnCell and OnDrawDataCell events to provide drawing for the cells.

The Options property enables you to set the display and behavior options for the grid. Using this property, you can turn off column titles, allow or disallow column sizing, turn row and column lines on or off, and so on.

The TitleFont property enables you to set the font for the column titles. You use the Font property to set the font for the grid cells.

The DBGrid has only two public methods. When using an owner-drawn grid, you can call the DefaultDrawColumnCell and DefaultDrawDataCell methods to ask VCL to draw the cell for you. This is useful if you are owner-drawing particular columns but you want default drawing behavior for the rest of the columns.

The DBGrid component has several events, most of which pertain to cell editing and data navigation. I won't list the events here because it is obvious from their names what functions they perform.

The DBNavigator Component

The DBNavigator component enables the user to browse a dataset record by record. The navigator provides buttons for first record, next record, previous record, last record, insert record, delete record, edit record, cancel edits, post edits, and refresh. This component is nearly automatic in that most of the time all you have to do is drop it on the form, hook it to a DataSource, and forget about it.

The ConfirmDelete property, when set to True, causes a dialog box to be displayed whenever the user clicks the Delete button. You set the Hints property to True to enable fly-over hints for each button on the navigator. The VisibleButtons property is a set that enables you to control which buttons show up on the navigator. You can add or remove buttons at design time or runtime.

The DBNavigator has only one method of interest and one event. You can use the BtnClick method to simulate a button click on the navigator. You can use the OnClick event to detect a click on the navigator. You rarely have to use OnClick, however, because the navigator already knows what to do when its buttons are clicked.

The DBText Component

The DBText component is the data-aware version of the standard Label component. It provides a way of displaying data from a field without enabling the user to modify the data. This component provides no database-specific properties, methods, or events other than those common to all data components.

The DBEdit Component

The DBEdit component provides an edit control that is linked to a field in a dataset. You used a DBEdit earlier today when you created a database form from scratch. The DBEdit component, like the DBText component, doesn't have any database-specific properties, methods, or events other than those common to all data components.

The DBMemo Component

The DBMemo is the data version of the standard Memo component. You can use this component to display data contained in database fields that contain large amounts of text. The AutoDisplay property controls whether the data in the dataset field is automatically displayed when the cursor changes to a new record.

When AutoDisplay is True, the data is automatically displayed. When AutoDisplay is False, the user must double-click the DBMemo to display the data (or press Enter when the control has focus). To force the memo to display its contents through code, you use a related method called LoadMemo. This method is appropriate only when AutoDisplay is False.

The DBImage Component

The DBImage component is used to display binary large object (BLOB) data that is stored in image format. DBImage isn't necessarily a read-only component. You can change an image by pasting an image from the Clipboard or by using the Picture property to load a file from disk. The following code will change the image at runtime:

DBImage1.Picture.LoadFromFile(`peregrine.bmp');

The main DBImage properties control how the image is displayed. They are described as follows:

Methods of the DBImage component include CutToClipboard, CopyToClipboard, and PasteFromClipboard. These methods do exactly what their names indicate.

The DBListBox and DBComboBox Components

The DBListBox component is, for the most part, a standard list box. What distinguishes it is that when the user selects an item in the list box, the selected item is written to the corresponding field in the dataset (set by the DataField property). To provide the strings the user can select from, you add strings to the Items property just as you do for a regular ListBox component. It is important to realize that the strings for the list box don't come from the database (that's what the DBLookupListBox is for).

The DBComboBox works in exactly the same way as the DBListBox except for the obvious differences between a list box and a combo box.

The DBCheckBox Component

You use the DBCheckBox primarily to display the contents of a database field containing logical data (True/False, Yes/No, On/Off). Set the ValueChecked property to a string that should be used to check for a match against the contents of the field. For example:

DBCheckBox1.ValueChecked := `On';

In this case, if the associated field contains the value On, the DBCheckBox will be checked. If the field contains a value other than the one specified, the check box will not be checked. You can supply more than one value to check in the ValueChecked property. For example:

DBCheckBox1.ValueChecked := `On;Yes;True';

If the value of the associated field contains any one of these values, the check box will be checked. The ValueUnchecked property works in exactly the same way except that any values matching the contents of ValueUnchecked will cause the check box to be cleared (unchecked). When specifying values for both ValueChecked and ValueUnchecked, the check box state will be indeterminate (grayed check mark) for field values that don't match.

The DBRadioGroup Component

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 the database.

The Values property holds the current value of the field in the database. You can use the Values property to substitute the display string in the radio group box with a different string. For example, you might have a radio group box with radio buttons labeled Yearly, Quarterly, and Monthly. Your database, however, might store codes such as Y, Q, and M instead of the full names. Given that scenario, you could set the Values property (a string list) like so:

Y
Q
M

Now, when a radio button is selected, the one-letter code will be written to the database field instead of the display string of the selected radio button. If the Values property is empty, the display string of the radio button will be written to the database when a radio button is clicked.

The DBLookupListBox and DBLookupComboBox Components

The DBLookupListBox component enables you to display a list of field values from a 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 properties to the dataset and field where the selection will be written. Set the ListSource and ListField properties to the lookup field from which the list should be populated.

The DBLookupComboBox works just like the DBLookupListBox. In addition, the DropDownAlign, DropDownRows, and DropDownWidth properties control how the drop-down list appears.

The DBRichEdit Component

The DBRichEdit component enables you to display and edit a rich text memo field in a dataset. The AutoDisplay property and LoadMemo methods of this component work exactly as they do for the DBMemo component.

The DBCtrlGrid Component

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 (or any other components for that matter), and Delphi will duplicate those components for each record in the dataset.

An illustration helps this explanation make more sense. Figure 17.12 shows a form containing a DBCtrlGrid component that has been aligned so that it fills the form's client area. The DBCtrlGrid contains a DBEdit, a DBMemo, and a DBImage. All the data components are placed on the first cell of the grid. The second cell contains a hatch pattern to tell you that you can't place components on that cell. Figure 17.13 shows the same form when the application is running.

FIGURE 17.12. A form at design time containing a DBCtrlGrid component.

FIGURE 17.13. The same form at runtime.

The DBCtrlGrid has a few properties worth mentioning. You use the Orientation property to determine where the scrollbar is to be placed and how the component acts when the scrollbar is clicked (the DBCtrlGrid in Figures 17.12 and 17.13 has the Orientation set to goHorizontal). You use the PanelWidth and PanelHeight properties to set the width and height of a cell in the grid. The RowCount property determines how many records to show at one time.

The DBCtrlGrid component has one event, OnPaintPanel. This event is fired each time a grid cell needs painting. You can respond to this event in order to draw on the background of the panel. This pertains only to the panel's background. Any controls on the grid will be painted automatically, so you don't have to worry about them.

Other Data Components

DBChart is a charting component included with the Professional and Client/Server versions of Delphi. This component is not only powerful, but also complex. I can't begin to explain everything the DBChart component does, so you'll have to experiment with it to discover all that it is capable of.

The Client/Server version of Delphi includes a tab named Decision Cube that contains six additional components. These components enable you to do complex data analysis such 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 be aware that these components exist in the Client/Server version of Delphi.

Summary

Well, that about sums up the art of building database forms. (Actually, I'm being facetious 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 forms from scratch for more flexibility. Either way you go, building good database forms takes time and experience to master. It isn't something that you can be great at overnight. On the other hand, it isn't terribly difficult, either. Keep working at it and you'll be a database whiz in no time. The important thing is knowing the data components available to you as you build your forms.

Workshop

The Workshop contains quiz questions to help you solidify your understanding of the material covered and exercises to provide you with experience using what you have learned. You can find the answers to the quiz questions in Appendix A, "Answers to the Quiz Questions."

Q&A

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?

A 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.

Q When using the Database Form Wizard, does it matter whether I create a form using TTable or TQuery objects?

A 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.

Q Is there any limit to the number of DataSource, Table, and Query components I can have on my form?

A There's no absolute limit, although there are practical limits to how many datasets you can work with at one time.

Q I noticed the DBEdit component doesn't have a Text property like the regular Edit component has. Why is that?

A 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.

Q Do I have to use a DBNavigator to enable my users to browse the database?

A 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.

	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?
A Make certain that you have the QuickDraw property set to True. Your images will draw faster, but they might not look as good.

Quiz

1. What's the fastest and easiest way to create a database form?

2. How do you control the order and number of columns that appear in a DBGrid component?

3. What component enables you to display a dataset in table format?

4. How can you add or remove buttons from a DBNavigator?

5. What component do you use to display BLOB image data?

6. What property is common to all data-aware components?

7. What property is used to select the field that a data component is linked to?

8. Can you rearrange the columns in a DBGrid component?

9. Which component is used to edit and display text fields in a database?

10. What does BLOB stand for?

Exercises

1. Create a new application that shows the contents of the VENDORS.DB table (DBDEMOS database).

2. Modify the application in step 1 so that only the VendorName, City, State, and Phone fields are displayed.

3. 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.)

4. Create a database form that uses a DBCtrlGrid component to browse a table. Use any table and include any fields you like.

5. 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.

6. Remove all buttons from the DBNavigator used in step 5 except the First, Next, Prior, and Last buttons.


Previous chapterNext chapterContents

© Copyright, Macmillan Computer Publishing. All rights reserved.