Ini configuration file

Source: Internet
Author: User

Here is a complete introduction to TIniFile objects: Using Delphi built-in functions to read and write INI files

After reading the above introduction, we started to read and write the INI file.

First, prepare an INI file in the same directory as the program. The file content is as follows:

[System]

Server = 127.0.0.1

DataBaseName = pubs

UserName = sa

Password =

Then, draw a form, add four Edit controls and a Button control, and use the default name.

Finally, write the code:

Implementation

Uses IniFiles;

Var

IFile: TiniFile;

{$ R *. dfm}

Procedure TForm1.FormCreate (Sender: TObject); {value of INI file read when the form is loaded}

Begin

IFile: = TIniFile. Create (ExtractFilePath (Application. ExeName) + 'data. ini ');

Try

Edit1.Text: = iFile. ReadString ('system', 'server ','');

Edit2.Text: = iFile. ReadString ('system', 'databasename ','');

Edit3.Text: = iFile. ReadString ('system', 'username ','');

Edit4.Text: = iFile. ReadString ('system', 'Password ','');

Finally

IFile. Free;

End;

End;

Procedure TForm1.Button1Click (Sender: TObject); {the value of the INI file written when you click the button}

Begin

IFile: = TIniFile. Create (ExtractFilePath (Application. ExeName) + 'data/data. ini ');

Try

IFile. WriteString ('system', 'server', Edit1.Text );

IFile. WriteString ('system', 'databasename ', Edit2.Text );

IFile. WriteString ('system', 'username', Edit3.Text );

IFile. WriteString ('system', 'Password', Edit4.Text );

Finally

IFile. Free;

End;

End;

Ini. Free;

End;

 

Var
Iserver, idatabasename, iUserName, iPassword: string;
IPort, itime: string;
Begin
IFile: = TIniFile. Create (ExtractFilePath (Application. ExeName) + 'pdaservice. ini ');

Try

Iserver: = iFile. ReadString ('data', 'server ','');

Idatabasename: = iFile. ReadString ('data', 'databasename ','');

IUserName: = iFile. ReadString ('data', 'username ','');

IPassword: = iFile. ReadString ('data', 'Password ','');

IPort: = iFile. ReadString ('Port', 'serviceport ','');

Itime: = iFile. ReadString ('time', 'interval ','');

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.