13th Chapter-DELPHI Development Database Application Overview (i) (3)

Source: Internet
Author: User
Tags create database

Architecture of 13.3 Delphi Database

Delphi uses visual parts to create database applications, like other non database applications, database parts have certain attributes, programmers can set a variety of properties in the design process, or in the process of the program to set the various properties of the part.

There are two pages of database parts on the Delphi Part Board for developing database applications:

Data Access Part Page: The parts on this page are mainly used to describe information about the database, such as the database to which the application will access (connect), the specific database tables to access the database, and which fields to access the table, and the parts commonly used in practical development applications are Tdatasource, ttable, Tquery and so on.

Data Control Part Page: The parts on this page are mainly used to display the data information in the browsing database, to provide users with a visual interface, commonly used parts are: TDBGrid, Tdbedit, Tdbcheck, etc., can let the user to the information in the database to effectively browse, edit, INSERT, Delete, and so on.

Ttable, Tquery, and tstoredproc parts are responsible for contacting and retrieving data from the actual database tables, and they are often referred to as dataset widgets that are visible during program design but are invisible when they are run by BDE Provides a connection to the database for the application, which is connected to the dataset by the Tdatasource part, provides a visual interface to the user, and displays the data information in the database.

13.3.1 Data Access part

A data Access Part Page provides a set of data access parts to access data in a database.

Figure 13.3 Data access parts on a data access page

When you want to create a database application, first select a data access part in the form, then the properties for the data Access part settings, the database to access, the datasheet, and the records in the table, and so on, the data Access part establishes a channel for the data control part and the data source. The data access part is not visible when the program is running. The following table lists the data access parts on the data access page and their primary uses:

Table 13.4 Data Access parts

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Part name main purpose

────────────────────────────

As a dataset part ttable, Tquery, StoredProc Group

Transfer of data between tdatasource pieces and data browsing Tdbgrid and Tdbedit

The channel.

────────────────────────────

It is the media that accesses the database table on disk, and it is saved by BDE

Ttable the data in the database table, ttable and Tdatasource

"Dialogue" allows the data browsing widget to effectively

Ttable access to data and can display and edit the data in it.

────────────────────────────

It accesses data in a database table on disk using the SQL language.

Tquery and Tdatasource "dialogue" to implement the data browsing widget

Access to the database.

────────────────────────────

Tstoredproc in the application, it is primarily used to access the remote server

Storage process

────────────────────────────

When the application wants to log on to a database on a remote server

When tdatabase, you can use this part to build an application and a database permanently

Sexual connection.

────────────────────────────

Tbatchmove is used to copy the structure of a database table or a record in a table.

────────────────────────────

Treport the output report used to create the database.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

It is worth pointing out that in most database applications, it is common to use a dataset part ttable, Tquery, or tstoredproc to connect to a database on disk, to connect Data control parts and dataset parts with Tdatasource parts, Of course, users can also customize dataset parts, for database applications, ttable, Tquery, and tstoredproc parts contain an invisible Tfield type of object fields,fields is a list of strings, It corresponds to a column or field of a database table or a query result. The Fields object is dynamically established with the active state of the ttable, Tquery and Tstoredproc parts, and when the database table is closed, the Fields object disappears, which is not visible in the process of program design and program operation.

Of course, you can also use fields editor to establish a permanent fields object for the Delphi application, we will explain in detail in later content.

13.3.1.1 ttable Parts

The Ttable Part program designer can access the database without even having to write any programs, and the process of placing a ttable part in an application form is as follows:

1. Select the data access page on the Component selection Board;

2, click the table icon;

3, click the mouse in the window to obtain a ttable part;

4, for the ttable part settings related to the properties:

The DatabaseName property specifies the path name of the database to be accessed, and the pathname can be represented by an alias.

The TableName property specifies that you want to access specific database tables in the database.

When the active property is set to True, opens the database table to be accessed, and when set to False, the database table to be accessed is not opened for the time being.

By default, the tttable part contains all the fields and records in the database table you want to access, and when you double-click the Ttable icon, a field editor (Fields Editor) appears, using the Fields Editor can edit properties such as the display format of a field in a database table contained in a ttable part to control:

Create a permanent list of fields, including the order of fields, the type of fields, and so on, even if the table structure of the actual database tables on the disk changes, the Permanent field list that we built will not change

Specify a name that is easy to read and use for each field

Specify the order in which fields are displayed

Specify a string to display for each field

Add legitimacy test to field

You can also create new fields (such as fields that can be calculated) for your needs. See the following

13.3.1.2 tquery Parts

The Tquery widget is a powerful tool for developing database applications in SQL language, because we can easily and flexibly access records in one or more database tables using the SQL language, so we can use Tquery to query local databases like pà? Aradox and dBASE database systems, we can also use the Tquery component to access a remote database SQL Server and establish a client/server-mode application.

The process of placing a tquery part in an application form is as follows:

1. Select the data access page on the Component selection Board;

2, click the query icon;

3, click the mouse in the window to obtain a tquery part;

4, for the Tquery part settings related to the properties:

The DatabaseName property specifies the path name of the database that will be accessed.

The SQL attribute specifies that the database table is accessed by an SQL statement that can be a query statement or a modified statement or INSERT statement. On the Object Browser, when you click the SQL property, a string editor opens for the program designer to enter the SQL statement.

Notice here that in the tquery part, instead of using the TableName attribute to specify the database tables in the database to be accessed, in the SQL attribute, the SQL statement specifies the database table that will be accessed.

13.3.1.3 tdatasouece Parts

The Tdatasource part is a bridge connecting the dataset parts ttable, Tquery, Tstoredproc and Data Control parts Tdbgrid, Tdbedit, etc., Ttable, Tquery, Tstoredproc parts can be accessed through the BDE to the database connection on disk, but they cannot display the data information in the database, but the data control parts such as Tdbgrid, Tdbedit can provide the visual interface, display the data information in the database, However, they do not have the ability to access the disk database, it is tdatasource to combine the two organically, so that users can interactively query, modify, insert, delete the data information in the database.

The process of placing a tdatasource part in an application form is as follows:

1. Select the data access page on the Component selection Board;

2, click the DataSource icon;

3, click the mouse in the window to obtain a tdatasource part;

4, for the Tdatasource part settings related to the properties:

The DataSet property specifies a dataset part, which can be the name of the ttable, Tquery, or Tstoredproc part.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.