首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

关于ini文件的操作,该怎么解决

2012-02-04 
关于ini文件的操作ini配置文件是这样的[dbinfo]Passwordxek_saUserNamesaHostSOFTdbNamecustomer对应

关于ini文件的操作
ini配置文件是这样的
[dbinfo]
Password=xek_sa
UserName=sa
Host=SOFT
dbName=customer

对应的程序如下:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TIniFile *theIniFile;
  theIniFile = new TIniFile(ChangeFileExt(Application->ExeName,".INI"));
  AnsiString captureMode = theIniFile->ReadString("dbinfo","Default","");
  AnsiString password = theIniFile->ReadString("dbinfo","Password","");
  AnsiString userName = theIniFile->ReadString("dbinfo","UserName","");
  AnsiString Host = theIniFile->ReadString("dbinfo","Host","");
  AnsiString dbName = theIniFile->ReadString("dbinfo","dbName","");
  delete theIniFile;
}

请大家帮帮我,告诉我这个ini文件究竟怎么用?我还是不会用

[解决办法]
这有什么不懂的?ReadStrin函数的参数1是[dbinfo],参数2是每个等号前的部分,参数3质空就可以表示读取默认值,你写的这段程序是读取ini文件的.如果你把theIniFile- >ReadString("dbinfo","Password","")附值给Edit->Text就能显示出xek_sa.试试看!!
[解决办法]
TIniFile *theIniFile; 
theIniFile = new TIniFile(ChangeFileExt(Application- >ExeName,".INI")); //".INI"写ini文件名字 
AnsiString captureMode = theIniFile- >ReadString("dbinfo","Default","");//dbinfo-字段名,Default-返回Default的值 //既Default=什么,""-如果没有Default则返回空 
AnsiString password = theIniFile- >ReadString("dbinfo","Password",""); 
AnsiString userName = theIniFile- >ReadString("dbinfo","UserName",""); 
AnsiString Host = theIniFile- >ReadString("dbinfo","Host",""); 
AnsiString dbName = theIniFile- >ReadString("dbinfo","dbName",""); 
delete theIniFile; 

需要include头文件:#include <IniFiles.hpp>
ReadString是读ini文件,WriteString是写ini文件
theIniFile->WriteString("dbinfo","UserName","ipxzerg");

热点排行