2 browsing and navigation
There are two different ways to create a form that access database data. The first method is to use the Database Form Expert. But unfortunately, database form experts can only handle BDE-Aware (visual BDE) subsets in dataset components. The second method is manually placed and connected to all data components.
Define user interface (defining the user interface)
We will establish your own data browsing form three steps. The first step is to define the user interface for the form; step 2, increase and configure data access components; the third step is the last step, add data visual control.
Turn off all open projects before you start. Then follow the steps:
Select File | New Application. This will create a new project, including an empty form, a unit and a project file;
Add a PageControl component on the form. This component is located on the WIN32 page of the component panel. Let it name the name: PageControl. Add TabSheets on pageControl (right click on pageControl and select "New page"). Set the title of the first Tablsheet1 as "Browse", the second is "Edit". Place a DataSource on your form, an adotable and an Adoconnection component. The name is all the default name. Select the first page of the PageControl component and place a DBGRID (Data Controls page) component on the Browse tab. Place a DBNAVIGATOR component (Data Controls page). The Navigator button is used to move the record in the table. By using the object viewer sets the connection between the components, as follows:
DBNavigator1.DataSource = DataSource1 DBGrid1.DataSource = DataSource1 DataSource1.DataSet = ADOTable1 ADOTable1.Connection = ADOConnection1 ADOConnection1.ConnectionString = ... ADOConnection1.LoginPrompt = False ADOTable1.Table = 'Applications'
Note: As discussed in the second chapter, the Connectionstring property indicates the physical location of the data store and our access. You can use the same connection string with the second chapter or build one by calling the connection string editor.
Set the LoginPrompt property of the Adoconnection component to false and prevent the database login interface. Since we don't have any password for the database, we don't need to log in.
Field (fields)
DBGRID components can be used when we want to provide users with the entire recordset (data in the table). Even if we can use DBGrid to add, edit, and delete records in the table - but the best way is to use the field object to each field in the table. Field objects are mostly used in the application of data display and editing in the application. By using the Fields Editor (field editor), we can set a fixed field object list for each column in the table. Field Editor can call by double-click DataSet component. In order to add a field to the fixed field list of the data set, right-click on the list and select Add Fields. In addition to all data in the table (in DBGRID), we also need to use the field-oriented data visualization components such as editing boxes. For example, the DBEDIT component is the data visual version of the TEDIT class. It is a building block for any data input program.
Place DBEDIT in the form and connect it to the field of the table as follows:
Call the Fields Editor by double-click the ADOTABLE component;
Select the Name field, such as an example. Let the second label of Page Control be an option;
Drag the Name field on the form.
When you put down the Name field on the label order, Delphi places a Label and a DBEDIT component on it. The Caption of the Label component is the same as the DISPLAYLABEL (Show tab) attribute being dragged. The DBEDIT component is connected to the data source of the data set through its DataSource property. If you select multiple fields from the field editor and place it on the form, Delphi will place the same multi-DBEDIT component on the form.
"It is alive!" (It's alive)
OK, what we need to do is to activate the connection and scroll records. Active component's Active property indicates whether we are connected to a table. Setting ACTIVE True or calls the Open method to make the CONONNECTED property of the Adoconnection component to True- and display data in the relevant data visual control.
First, then, finally ... (first, move by, last, ...)
Now we are final preparation. Let's take a look at how to browse records.
The DBNAVigator component provides a friendly and simple tool for the browsing record set. In addition to its browsing capabilities, DBNAVigator also provides ways to operate data such as insert, delete, or cancel. For example, if we click the DELETE button, the corresponding record will be removed from the recordset. Each button is optional, you can combine and match them at will.
With the button setting, we can jump to the last record or move to the previous record. For example, click the Last button to set the last record currently recorded as the recordset and invalidate the last (last) and NEXT (next) buttons. Clicking the Last button has the same effect as the last method of calling the dataset.
It should be noted that one of the browsing operations that DBNAVigator cannot handle is to move forward or backward movements on a certain number of intervals. The Moveby method of the data set is used to locate the location of any of the records currently recorded relative to the recordset.
This is this chapter. Now we will prepare for the editing and query of the data set, which will explain in the next chapter of this tutorial ...
December 26, 2002 20:49