Delphi database programming tutorial
Title note : A free online tutorial for Delphi beginners to write database programs, focusing on ADO technology.
About this tutorial : It is a free online tutorial completely aimed at beginners of Delphi database programming, and can also be used as a reference for those who want to understand the art of Delphi database programming. Developers will learn how to design, develop, and test database applications using Delphi and ADO technologies. This tutorial focuses on the most common methods of using ADO in database applications: using TADOConnection to connect to the database, using Tables and Queries, handling database exceptions, creating reports, etc.
Prerequisites : Readers should have working knowledge of the WINDOWS operating system and certain knowledge of Delphi programming. New beginners can first refer to the "Beginner's Guide to Delphi Programming" (I will translate it when I have time).
Chapter 1 Basics of Database Development (using Delphi)
Section 1 Database Programming Tool Delphi
Many Delphi beginners start Delphi programming by writing a program like "MyNotepad", while other developers work day and night writing multimedia and graphics applications, but sooner or later they will realize that 90% of today's software will be related to the previous ones. Some kind of data interaction and impact stored in a certain way.
One thing is beyond doubt: Delphi is effective and reliable in data management. Application developers building the next generation of business software are attracted to Delphi for a reason: Using Delphi, we can develop software that operates on all types of desktop databases, such as Paradox, dBase or MS Access. Using Delphi, we can also get C/S solutions.
Data Access with Delphi... just a few Words
Delphi comes with more than 40 pre-built database components and provides a visual programming environment - including an integrated code editor, Database Form wizard - to speed the creation of browsable database forms, and a data module designer ( Data Module Designer)--used for data access sharing between multiple forms. There are several other database-specific tools provided by Delphi that can also speed up code generation and reduce the difficulty of programming.
The Data Access page of the component panel provides components for connecting to data sources. The data visualization component in the Data Controls page is used to obtain data from or send data to the database. The components of the ADO page use ActiveX Data Objects technology to access database information through OLE DB. The components of the InterBase page are used to directly access the InterBase database.
Don't runaway
Of course, database programming is not trivial and worth mentioning. In this course, we will try to bring you the latest technologies, problems and solutions for database programming with Delphi, as well as all the secrets hidden from us.
Before using Delphi's various data components and tools, we should first understand some concepts of database design and try to design a simple database.
Section 2 Create a new database
Before we start interacting with a database using Delphi, it's a good idea to understand the characteristics of modern databases. When you see the word database, you usually think of various kinds of data stored on your computer—even a .pas file (the source code for some Delphi units) is some kind of database, and other types of databases are a Word database. document or a simple .ini file. To access an .ini file, we typically use routines and techniques for typed or untyped files.
Building modern database applications requires us to think about data in a relational way. The basic idea of the relational model is that a database consists of a series of tables (or relationships) that can be manipulated by operators and return tables or so-called views. Simply put, a database is best described as a collection of related data. A database can contain many different tables, represented by many grids - columns are called fields (fields), rows are called... rows (translator added: or records)
In order to fully understand the concepts of database design and relational models, we need to study additional online tutorials - "Fundamentals of Relational Database Design" (Translator's addition: Translated in succession).
New ...Database
Since the focus of this tutorial is to introduce the Delphi database programming method of ADO/Access, now we will learn how to create a new .mdb database in MS Access.
If you have never created an MS Access database, you can refer to "MS Access Tutorials" (Translator's addition: Translated in succession).
Run MS Access and create a new empty database named aboutdelphi.mdb. Create three tables in the design window: applications, authors, and types. Let's see the structure of these tables:
The Applications table contains fields that match the application description requirements: Name, Description, Author, Type, Size, Cost, DateUpl, and Photo (Picture). The Name, Description, Author, and Type fields contain text data, with a default length of 50 characters. The size field (Size) is of type Number (Single) - stores the size of the file in Kb. The Cost field is the Currency field - if the application is shareware or commercial software. The DateUpl field is a Date/Time value. Photo (Picture) is an OLE Object type that holds the application's photo (optional). Set the Name field as the primary keyword.
The Authors table contains fields that match the application author requirements: AuthorName, Email, and Web. All fields contain character data (default is 50 characters). Set the author name (AuthorName) field as the primary keyword.
The type table (Types) contains only one field: type name (TypeName), which is also the primary key of the table. This table is used to store the type of application (graphics, multimedia, database...).
Now we only need to establish the relationship in the relationship window, and the database creation is completed.
The relationship should be "Enforce Referential Integrity" and check "Cascade Update Related Records".
December 19, 2002 22:38