1. 程式人生 > >BCB對如何操作ini檔案?

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