//包含文件
#include <inifiles.hpp>
//写文件
TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));
ini->WriteInteger("connection","User",User);
ini->WriteInteger("connection","Password",Password);
ini->WriteString("connection","Caption",Caption);
ini->WriteBool("Form","InitMax",WindowState==wsMaximized);
delete ini;
//读文件
if(FileExists(ExtractFilePath(Application->ExeName)+"config.cfg"))//检测文件是否存在
{
TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));
Top=ini->ReadInteger("Form","Top",100);
Left=ini->ReadInteger("Form","Left",100);
Caption =ini->ReadString("Form","Caption","Default Caption");
ini->ReadBool("Form","InitMax",false)?WindowState=wsMaximized:WindowState=wsNormal;
delete ini;
}
else
{
ShowMessage("文件不存在");
}
ini文件
配置文件名:config.ini
配置文件内容:
*******开始********
[connection]
User=sa(用户名)
Password=密码
Server=服务器名
Database=数据库名
*******结束***********