BCB对如何操作ini文件?

      .ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式,统管windows的各项配置,在实际开发中, ini文件的应用也是非常广泛的。

     下面来利用BCB来操作一下ini文件:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

#include <inifiles.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TIniFile *IniFile = new TIniFile(ExtractFilePath(Application->ExeName) + "test.ini");
    IniFile->WriteString("FirstSection", "IDE", "Borland C++ builder");
    delete IniFile;
}
//---------------------------------------------------------------------------
       点击按钮后,就会产生test.ini文件, 内容为:

[FirstSection]
IDE=Borland C++ builder


       上面只讲了WriteString方法, 其实还有很多:

DeleteKey
EraseSection
ReadSection
ReadSections
ReadSectionValues
ReadString
TIniFile
UpdateFile
WriteString
ReadBool
ReadDate
ReadDateTime
ReadFloat
ReadInteger
ReadTime
SectionExists
WriteBinaryStream
WriteBool
WriteDate
WriteDateTime
WriteFloat
WriteInteger
WriteTime
ValueExists


你可能感兴趣的:(BCB对如何操作ini文件?)