15th chapter-Application and programming of data access parts (i) (1)

Source: Internet
Author: User
Tags inheritance table name

In this chapter we mainly introduce the Delphi data Access components of the hierarchy, the relationship between the components, the components of the attributes, methods, events and the application of the components. These components include:

TSession Parts

DataSet Widgets (Ttable and Tquery)

Tdatasource Parts

Field Object Tfield

Use of the field editor

Treport Parts and Tbatchmove parts

We have a general description of the attributes, methods, and events of these parts, and readers can also get more detailed information about the parts by online help when they actually use Delphi to develop the application.

15.1 Delphi data Access part hierarchy

Delphi provides a powerful ability to develop database applications, providing users with a large number of data access parts. To facilitate the development of database applications by program designers. Some of these parts inherit the properties, methods, and events of other parts, which means that there is an inheritance and inheritance relationship between the multiple parts, and this association of the parts constitutes a hierarchy

Figure 15.1 Delphi data Access part hierarchy

TSession is a global component that is automatically built when the application is running and is an invisible part in the design phase and in the running process.

The tdatabase part is the parameter of the login database set up for the client/server database application, which is on the data Access part Page.

Tdataset parts are invisible, and the ttable and tquery parts are derived from it, which are commonly referred to as DataSet parts, which are on the data Access part Page.

The Tdatasource part is a bridge between the data set part and the data browsing part, on the data Access part Page.

The Tfields part corresponds to the actual field in the database table, which can be generated dynamically during the running of the application or in the field editor during the program design phase. It is an invisible part in the program where we can access the values of each field in the database record through the Tfield part.

15.2 tsession parts and their applications

TSession parts are generally used less, but they are useful for some special applications, and Delphi automatically creates a tsession part when each database application runs. The programmer can neither see the part nor display it to create a tsession part, but we are able to use the properties and methods of the tsession part globally in the application.

Important properties and functions of 15.2.1 tsession components

Many of the important properties of the tsession part are used to control the connection between the database application and the database, in an application where you can set the value of the tsession for the global setting and control the database on the disk to which it is connected. The tsession part has the following attributes:

Database property: Is the list of names of all the databases in the tsession that can be connected, often the names of the actual databases, including the database path, user name, user logon password, and so on.

Databasecount property: Is the number of all databases in the tsession that can be connected, which is an integer.

Keepcounnections property: Is a Boolean property that shows whether the application maintains a connection to an inactive database. Because for a database, when no corresponding dataset part (ttable or Tquery) is opened in the database, the database automatically becomes inactive. By default, the value of Keepcounnections is true, which means that the application always maintains a connection to the database, even when the database becomes an inactive database. If you set the Keepconnections property to False, the connection between the application and the database is interrupted when the database becomes inactive from the active state.

Netfiledir property: Describes the path name of the BDE network control file.

Privatedir property: Describes the path name for accessing temporary files.

Methods of 15.2.2 tsession parts:

Most of the methods in the TSession part are used to provide users with information about the database to which the application is connected, such as the name and alias of the database, the table name in the database, and the parameters of the database engine BDE, to obtain information about the database when designing the database application. Invoking the following methods of the tsession part will greatly simplify the design of the program.

Getaliasnames Method: Call this method and we can get the database alias defined in the database engine BDE.

Getaliasparams method: This method is mainly used to obtain the parameter values that we describe when we define the database alias in BDE, such as the directory path where BDE is located, and the actual name.

Getdatabasenames method: Calling this method can help us get the names of all the databases that the current application can connect to, and the name of the database is the alias of the actual database defined by the user using the BDE tool.

Getdrivernames method: Database engine BDE can be connected to a variety of database management systems, such as client/server database management system Oracle, Sybase, and local database management system Dbase,paradox, BDE when you connect to each database management system, you have the appropriate drivers, and these drivers are optionally installed. By calling the Getdrivernames method. We can get the name of the current BDE installed database driver.

Getdriverparams method: The BDE database driver contains multiple parameters, such as the supported national language, the version number of the DBMS, the file block size, and so on, for the DBMS on the server, the name of the database server, and so on.

Gettablenames method: Because each database is composed of multiple database tables, we can get the names of all the database tables in the database by stating the database name and then invoking the Gettablenames method.

All of these methods require a list of strings as arguments at the time of invocation, and both return a value for the list of strings.

TSession Part There is also a method called Dropconnections that controls the connection of the application to the database, and when the Dropconnections method is invoked, the connection between the application and all the databases will be cut off.

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.