关于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");