|
main_TK 님이 쓰신 글 :
: TIniFIle 클래스의 속성을 이용해서... 특정 섹터의 내용을 지우고, 또는 섹션이름을 변경하는 방법 싶은데요..
:
: 섹션 추가는 알겠는데... 지우거나 특정세션의 이름을 변경하는 건 어떻게 해야 할지 모르겠습니다.
: 답변주십시요..감사합니다..
TINIFile의 EraseSection, DeleteKey 메서드를 이용하시면 원하시는 작업을 하실 수 있을 겁니다.
이름을 변경하는것은 기존 섹션이나, 키를 값을 읽고 다른 이름의 섹션/키 값으로 Write 하시면 되겠죠..
사용 예는 Builder의 Visual component Library Reference Help TIniFile의 example에 있습니다.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TIniFile *pMyIniFile = new TIniFile("\\usr\\MyApp.ini");
Memo1->Clear();
pMyIniFile->ReadSectionValues("Transfer", Memo1->Lines);
if (Memo1->Lines->Values["Title1"] != "Picture Painter")
pMyIniFile->WriteString("Transfer","Title1","Picture Painter");
delete pMyIniFile;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TIniFile *pMyIniFile = new TIniFile("\\usr\\MyApp.ini");
// if the entry wasn뭪 there before, delete it now
if (Memo1->Lines->Values["Title1"] == "")
pMyIniFile->DeleteKey("Transfer", "Title1");
// otherwise, restore the old value
else
pMyIniFile->WriteString("Transfer", "Title1", Memo1->Lines->Values["Title1"]);
delete pMyIniFile;
}
|