When designing a database application, it is often necessary to separate some information from the program in order to ensure the portability of the program. The most important information is the connection parameters of the database.
In Delphi, the way to get the correct database connection parameters is very simple, you only need to create a data module, in which you add an ADO Connection, double-click it, and then select "Use Connection String" in the pop-up window, click "Build" button , select the appropriate driver engine in the Data Link Properties window and set the appropriate connection parameters. When you click "Confirm", the system will automatically generate the connection string, which is displayed in the connection string of object Inspector.
For example, in Microsoft SQL Server, the connection string is similar to the following:
Provider=SQLOLEDB.1;Password=map;
Persist Security Info=True;User ID=map;
Initial Catalog=SuperWorkFlow;Data Source=GTSERVER
The parameters of the connection string are separated by semicolons (;), with the following meanings:
provider--Drive Type
Data source--Server Name
Initial catalog--Database name
User id--username
password--Password
Persist security info--Whether or not to use persistent secure authentication
The first thing we need to do now is to write the parameters into an INI file. Windows INI file, which can be interpreted as a Windows initialization file. It is a text file that is designed to hold application initialization information and run environment information. For example, the two well-known INI files in Windows 3.1 Win.ini and System.ini define settings such as mouse response speed in Windows environment, shell program used, and so on when Windows starts. Many of the applications shipped with Windows systems also have their own INI files. The acquisition and preservation of Windows software initialization parameters is accomplished by reading a text file with the extension ini. That is, the program before running from the development of the INI file to search for the required parameters, and reflected in the program's operating environment, when the program exits the current environment parameters are saved to the development of the INI file.
INI file is a text file, composed of several section, under each parenthesized heading, is a number of keyword and an equal sign, each keyword will control the operation of a function of the application, the value on the right side of the equal sign to develop the operation of keyword, The general form is as follows:
[section1]
keyword1=value1
keyword2=value2
[section2]
keyword1=value1
keyword2=value2
Where SectionName and KeywordName are segment names and keywords, value is the set value for the keyword, and if nothing on the right side of the equals sign (value is empty), the Windows application has specified a default value for the keyword. If you cannot find a keyword in the entire file, you also specify a default value for them, and the order in which the sections appear is irrelevant, and the order of each keyword is irrelevant in each section, Keyword values are of type string or integer and should be read and written in two cases.
INI file writing has strict requirements:
1. The name of the section must be "[" and "]", and "[" must be in the first column of the screen.)
2, keyword name must also be written from the first column of the screen, and must follow the "="