Delphi 3.0 provides strong support for accessing databases, and powerful database applications can be developed using Delphi 3.0.
---- Delphi's visualization function is quite powerful. It is very easy to create a simple program that only views and maintains data. You can do it without writing any code! There are three ways to access the database in Delphi 3.0: direct access, such as access to Paradox and DBase databases; access through ODBC, such as access to access, FoXPRo and other databases; access to the database through embedded (Native) methods, such as access to SQL Server, Oracle, DB2 wait. In Delphi, you can use the Table control or/and the Query control to access the database. The settings and usage of the two are similar, so the following only uses the Table control as an example to illustrate the characteristics and usage of these three methods.
---- 1. Direct access
----Delphi can directly access Paradox and DBase, two desktop database systems. No special settings are required to access these two types of databases. You only need to assign the file path to the property DatabaseName of the Table control to access the database under this path. Of course, you can also create a database alias that maps the database path in advance, and then set the DatabaseName property of the Table control to the corresponding database alias.
---- 2. Access via ODBC
---- Accessing databases other than Paradox and DBase is usually achieved through ODBC. Delphi can access database systems that support ODBC, such as Access, SQL Server, and Oracle. Of course, when accessing the database through ODBC, you must first use the Windows Control Panel or Delphi's Database Engine (BDE) to establish an ODBC data source.
---- Delphi provides the Database control. The functions of this control are: establishing a connection with the database system and performing transaction processing under the control of the application program. In database applications, you can use the Database control or not. If you do not use the Database control, you can directly assign the name of the ODBC data source to the property DatabaseName of the Table control to achieve the purpose of accessing the database. The disadvantage of this method is that the Delphi system automatically pops up the English interface window for logging in to the database when the program is running, which is neither beautiful nor easy to control. Therefore, the author recommends using the Database control in database applications to log in to the database system. The way to associate a Table control with a Database control is to specify the value of its DatabaseName property as the value of the DatabaseName property of the Database control. A Database control can manage several Table controls. After establishing association with the Database control, as long as the Database control has established a connection with the database, the Table control can directly access the database without logging in again.
---- 3. Access via embedded mode
---- In Delphi, you can access database systems such as SQL Server, Oracle, and DB2 in an embedded manner without using ODBC. This requires using a database alias to specify the database. The database alias can be established in advance or dynamically created when the program is running. The former is called a static alias, and the latter is called a dynamic alias. The method of using a database alias to access the database is the same as using an ODBC data source, and will not be described again here. Static aliases for inline access to the database must be established in the BDE. Taking accessing the SQL Server database as an example, when establishing an alias, you must specify the name of the database server (SERVER NAME), the host name (HOST NAME) and the name of the database to be accessed (DATABASE NAME). You can specify the login user name (USER NAME) and Password (PASSWord), etc. Accessing the database through dynamically created aliases requires the use of the Database control.
---- in conclusion
---- Compared with accessing the database through ODBC, the former is faster than accessing the database through the embedded method. Moreover, the embedded method can dynamically set the parameters required to connect to the database in the program, and the user does not have to set up an ODBC data source, which reduces the requirements for the user's technical level and reduces the user's workload. From the perspective of the ease and complexity of system configuration, database application systems developed using the embedded method are more convenient for ordinary users to use. Therefore, the author recommends that when developing larger application systems, it is best to access the database through embedded methods.