Delphi is a visual software development tool developed by the famous Borland company. There is a sentence that most classic and appropriately describes Delphi - "Real programmers use C, smart programmers use Delphi." Many people call Delphi the fourth generation programming language, which has the characteristics of simplicity, efficiency and powerful functions. Compared with Visual C++, Delphi is simpler and easier to learn and master, but it is not inferior in function; compared with Visual Basic, Delphi is more powerful and practical. It can be said that Delphi has both the characteristics of VC and VB, so it has always been a programming tool that most programmers love.
Below, we will briefly introduce the characteristics of Delphi, commonly used components, as well as the methods and steps for using Delphi to develop database programs.
Since its development, Delphi 1, Delphi 2 to the present Delphi 7, Delphi 8 (Borland Delphi .net), Delphi has continuously expanded and improved its functions, features and advantages. Delphi provides a variety of development tools, including integrated environments, image editors, and various database applications, such as Database Desktop. In addition, users are allowed to attach other application development tools, such as Borland's Resourse Workshop.
Among Delphi's many advantages, its database expertise is particularly prominent: it is suitable for a variety of database structures, from client/server mode to multi-layer data structure mode; efficient database management systems and a new generation of more advanced ones Database engine; the latest data analysis means and provide a large number of enterprise components.
First, let’s briefly understand how Delphi accesses databases.
Delphi's database operation is mainly carried out using BDE (the abbreviation of Borland Database Engine). Of course, directly accessing the database through other methods can also be achieved in Delphi. However, for local databases, accessing data through BDE is very efficient. If you can be proficient in operating local databases, it will be easy to write network databases. Especially for beginners, the chances of writing network databases are not as high as those of stand-alone local databases. So, we focus on local databases.
BDE is an intermediate medium responsible for communication between users and databases. In fact, the application connects the component and the BDE through data access, and then the BDE accesses the database to complete the operation of the database, rather than directly operating the BDE. In this way, users only need to care about the data components in Delphi and do not have to deal with BDE directly.
Database components are mainly divided into two categories: "data access components" and "data control components". Their relationship with the database can be illustrated by the following relationship diagram:
With BDE, almost all types of databases can be operated. Next, let’s briefly introduce the commonly used database components in Delphi.
1. Data access component
The data access component can be found on the Data Access component page of the Delphi component panel. Here we should note: Table, Query and StoredPRoc controls are called "dataset components" and are used to connect to the database. Learners can treat these controls as "virtual" databases, and their operations can be considered operations on the database.
(1) The DataSource control is the connection medium between the data set components and the data control components. The data control component is the interface for users to operate data in the database. It can only be connected to the dataset component through the DataSource control, so as to display, modify, maintain and other operations on data.
(2) Table controls access data in the database through the database engine - BDE. Pass the user's operations on the database (such as adding, deleting, modifying, etc.) to the database through BDE.
(3) The Query control uses SQL (Structured Query Language) to operate the database through BDE, and it is similar to the functions completed by the Table control. It only uses SQL to implement it.
(4) The Storedproc control operates on the server database through BDE and is often used in database applications with client/server (C/S) structure.
(5) DataBase control is generally used to establish a remote database server - the connection between the database application and the database with a client/server structure.
(6) The session control is used to control database applications and database connections, and is mainly used for the implementation of complex functions, such as multi-threaded database programming.
2. Data Control Component
The data control component may also be referred to as a data display component or a data browsing component. Their main function is to cooperate with the data access component to provide users with an interface for browsing, editing and other operations on data. The data control component is on the DataControl page on the component board. They mainly include: DBGrid control, DBNavigator control, DBText control, DBEdit control, DBMemo control, DBImage control, DBListbox control, DBComboBox control, DBCheckBox control, DBRadioGroup control, DBLookupListBox control, DBLookupComboBox control, DBRichEdit control, DBCtrlGrid control, DBChart control, etc.
In addition, there are some components related to the database. For example, Decision Cube is a set of controls mainly used for data statistics, expressing statistical results in intuitive ways such as tables or graphics. QReport is a control used to output reports, but, based on experience, this control is not suitable for Chinese reports. This component was purchased by Borland, and its performance is not very good, so it is not used many times now. At present, some report controls provided by third-party controls are very useful, and some report controls made by Chinese people themselves are very suitable for the habits of Chinese people.
Another component page is ADO (ActiveX Data Objects), which mainly uses Microsoft's OLE DB function to access and operate data in the database server. Its main advantages are ease of use, high speed, low memory payments and less storage space. ADO supports the establishment of client/server and web-based applications. ADO also has the remote data service (RDS) function. Through RDS, it can move data from the server to the client application or web page during a round trip, process the data on the client and then return the update result to the server. ADO is becoming more popular now, and ADO itself is also very complicated. Microsoft has special help documents to explain how to use ADO. Learners who are interested can find relevant materials to learn more.
Writing a program
After the preparations above were completed, it should be said that one-third of the Long March had been completed. Because of the clear program flow, basic and sufficient programming resources, and possible difficulties, we have found solutions. It can be said that "everything is ready, but we only need the east wind"! Because we have prepared in advance, even if we may encounter some difficulties in the future when writing the program, it will not become a "stumbling block". All we need to do is to take out a lot of time, calm down and follow it carefully Programs and processes are written. Here we explain that before writing a program, you should first establish a blank database. Of course, you can also establish a database when designing the plan, or you can also establish a blank database before officially writing the program after completing the previous five steps.
Some suggestions for writing database programs
Since the database program has many interactive functions and the user has a large amount of data that users need to input, the program's error handling must be fully considered, and the user may have input errors should be fully considered and promptly given in the program.
Verify the input data during saving to prevent some illegal data from being saved in the database, resulting in errors in subsequent statistics and queries.
It is not easy to write a program with good stability and strong fault tolerance. From experience, a large part of the energy is spent on preventing errors and allowing the program to run stably.
After completing the code of a functional module, you must debug it immediately. After the debugging is passed, write the code for another function. This can prevent the code from being debugged after the code is finished. Because of the possible mutual influence, it is impossible to clear which part of the code. There is a problem.
You need to add some comments to the key parts of the code in case you can't understand how you wrote it in the future. Back up the program code and prepare for "disaster recovery". (Full text ends)