讀取修改ini的問題 |
|
tippler
一般會員 發表:1 回覆:2 積分:0 註冊:2006-11-06 發送簡訊給我 |
我想在一個Edit中輸入一個名稱(如PAD_2),然後按下一個SpeedButton,傳到ListBox中(ListBox中顯示ini的所有Section,其中有PDA_1)傳進去後PDA_2的value會等於PDA_1的value
等於在ini中新增一個Section,但是新增的section的value和同性質的section內容是相同的 [PADS_GRIP_PAD_19] ALIAS_ID=19 ALIAS_11=ON ALIAS_22=OFF OO_TWINS=0 INP_1=63 OUT_1=43 PNP_1=1 TIM_1=2 新增在Edit輸入PADS_GRIP_PAD_20 [PADS_GRIP_PAD_20] ALIAS_11=ON ALIAS_22=OFF OO_TWINS=0 INP_1=63 OUT_1=43 PNP_1=1 TIM_1=2 以下是我寫.... int __fastcall TForm1::i32RetrievalSections() { for (int i = 0; i < FileListBox1->Items->Count; i ) { if (FileListBox1->Selected[i] == true) { AnsiString szFilename = FileListBox1->Directory String("\\") FileListBox1->Items->Strings[i]; if (S16 != NULL) delete S16; S16 = new TIniFile(szFilename); S16->ReadSections(ListBox1->Items); break; } } return 0; }//-------------------------------------------------------------------------- int __fastcall TForm1::i32RetrievalValues() { if (S16 == NULL) return -1; for (int i = 0; i < ListBox1->Items->Count; i ) { if (ListBox1->Selected[i] == true) { S16->ReadSectionValues(ListBox1->Items->Strings[i], ValueListEditor1->Strings); szCurrentlySection = ListBox1->Items->Strings[i]; Edit1->Text = ListBox1->Items->Strings[i]; break; } } return 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::FileListBox1Change(TObject *Sender) { Label5->Caption = FileListBox1->FileName; i32RetrievalSections(); if (ListBox1->Count <= 0) return; ListBox1->ItemIndex = 0; SpeedButtonSaveValues->Enabled = (i32RetrievalValues() == 0); SpeedButtonEdit->Enabled = (i32RetrievalValues() == 0); } //--------------------------------------------------------------------------- void __fastcall TForm1::ListBox1Click(TObject *Sender) { SpeedButtonSaveValues->Enabled = (i32RetrievalValues() == 0); } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButtonSelectFolderClick(TObject *Sender) { int iRetrievalFileState = i32RetrievalInfFiles(); if (iRetrievalFileState == 0 && FileListBox1->Count > 0) { FileListBox1->ItemIndex = 0; FileListBox1Change(Sender); return; } else { ListBox1->Clear(); ValueListEditor1->Strings->Clear(); } SpeedButtonSaveValues->Enabled = false; SpeedButtonEdit->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButtonSaveValuesClick(TObject *Sender) { if (S16 == NULL) return; for (int i=0; i { S16->WriteString(szCurrentlySection, ValueListEditor1->Strings->Names[i], ValueListEditor1->Strings->Values[ValueListEditor1->Strings->Names[i]]); } 請個位前輩能否幫幫忙,感激不進 |
tippler
一般會員 發表:1 回覆:2 積分:0 註冊:2006-11-06 發送簡訊給我 |
|
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
|
tippler
一般會員 發表:1 回覆:2 積分:0 註冊:2006-11-06 發送簡訊給我 |
我是把iniFileSection,Copy出來,比如把Section,Copy到Edit中,在Edit中改Section的名稱再copy加到iniFile中
ListBox1是顯示出Section,ValueListEditor1是顯示內容 for (int i = 0; i < ListBox1->Items->Count; i ) { if (ListBox1->Selected[i] == true) { Edit1->Text = ListBox1->Items->Strings[ListBox1->ItemIndex]; SpeedButtonAdd->Enabled = true; SpeedButtonDelete->Enabled = true; } } for (int i=0; i { S16->WriteString(Edit1->Text, ValueListEditor1->Strings->Names[i], ValueListEditor1->Strings->Values[ValueListEditor1->Strings->Names[i]]); } ListBox1->Items->Add(Edit1->Text); Edit1->Clear(); |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |