新建配置文件IP.ini,文本内容:
[database]
IP=192.168.1.253
Port=8000
UserName=admin
PassWord=k123456
[CfgIni]
AutoRun=1
AutoClose =0
[StrIni]
StringName = Hello
ini文件由节(database,CfgIni,StrIni)、键(IP,Port,UesName,PassWord等)、值(192.168.1.253,8000,admin,k123456)组成,
获取ini文件中的数据
头文件加#include"IniFiles.hpp"
char dir[MAX_PATH];//----获取运行程序的目录开始
char *tfile = "\\IP.ini";//将程序现在目录所在输入此字符数组
::GetCurrentDirectory(MAX_PATH,dir);//将现在目录加上指定文件名
strcat(dir,tfile);//----获取运行程序的目录结束
TIniFile *ini = new TIniFile(dir);
m_ctlDvrIP->Text=ini->ReadString("database","IP","127.0.0.1");
m_nPort->Text=ini->ReadString("database","Port","8000");
m_strUserName->Text=ini->ReadString("database","UserName","admin");
m_strpwd->Text=ini->ReadString("database","PassWord","123");
m_Run->Text=ini->ReadString("Cfgini","AutoRun","10");
m_StringName->Text=ini->ReadString
delete ini;
函数原型 ReadString(cUnicodeString Section, UnicodeString Ident, UnicodeString Default);
Section为ini文件的节(database,CfgIni,StrIni);
Ident为ini文件的键(IP,Port,UesName,PassWord等);
Defauit为默认值,当获取失败时函数返回Default;
写入数据到ini文件
头文件加#include"IniFiles.hpp"
char dir[MAX_PATH];//----获取运行程序的目录开始
char *tfile = "\\IP.ini";//将程序现在目录所在输入此字符数组
::GetCurrentDirectory(MAX_PATH,dir);//将现在目录加上指定文件名
strcat(dir,tfile);//----获取运行程序的目录结束
TIniFile *ini = new TIniFile(dir);
ini->WriteString("database","IP",m_ctlDvrIP->Text);
ini->WriteString("database","Port", m_nPort);
delete ini;
函数原型void WriteString(UnicodeString Section, UnicodeString Ident, UnicodeString Value);
Section为ini文件的节(database,CfgIni,StrIni);
Ident为ini文件的键(IP,Port,UesName,PassWord等);
Value为要写入的值。