全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:929
推到 Plurk!
推到 Facebook!

添加到INI文件中

尚未結案
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-28 16:06:02 IP:218.5.xxx.xxx 未訂閱
我曾提了个问题,名为“对INI文件的操作 ”,后经Wnhoo兄指点,问题解决了。原文见"http://delphi.ktop.com.tw/topic.php?TOPIC_ID=31053"。 现我想通过TComboBox对INI文件进行操作,即ComboBox1KeyDown,则 关键字:=ComboBox1.Text,加入到INI文件中,且INI文件的关键字只10项,新加入的在第一项,将第十一项删除。我的代码如下: //STAT1.INI [System] VESA=1 ScreenMode=VM_800X600X256 SystemCharSize=16 CurrentGroup=WORD MainTitle1=ok MainTitle=1987 uses INIFILES; procedure listTitle1; procedure FormCreate(Sender: TObject); procedure ComboBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure TForm1.listTitle1; var filename:string; i:integer; breedno:tstringlist; inifile:TINIFILE; begin comboBox1.Clear; //取得文件路径 filename:=ExtractFilePath(paramstr(0)) 'stat1.ini'; inifile:=TInifile.Create(filename); breedno:=tstringlist.create; inifile.ReadSection('System',breedno); for i:=0 to breedno.Count-1 do combobox1.items.add(breedno.Strings[i]); breedno.Free ; inifile.Free ; end; procedure TForm1.FormCreate(Sender: TObject); begin listTitle1; end; procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var filename:string; inifile:TINIFILE; begin if key=VK_Return then begin comboBox1.Clear; //取得文件路径 filename:=ExtractFilePath(paramstr(0)) 'stat1.ini'; inifile:=TInifile.Create(filename); inifile.WriteString ('System',combobox1.Text,' '); inifile.UpdateFile ; inifile.Free ; listTitle1; end; end; 但无法将ComboBox1.Text加入到INI文件中,且即便添加成功,也是加为最后一项,如何加为第一项?
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-28 16:42:33 IP:210.241.xxx.xxx 未訂閱
我可以請問一下嗎,你寫入都依session ident 寫入 為什麼要放在最前面,有差嗎?
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-28 16:58:08 IP:218.5.xxx.xxx 未訂閱
因为新输入的内容可能更重要,所以放在ComboBox1列表的最上面。
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-28 17:47:27 IP:210.241.xxx.xxx 未訂閱
那你可以直接把ComboBox1的TEXT設成那個字串就好了
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-29 10:20:15 IP:218.5.xxx.xxx 未訂閱
inifile.WriteString ('System',combobox1.Text,' '); 但无法将combobox1中Text写入Ini中,为何?
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-29 10:55:32 IP:210.241.xxx.xxx 未訂閱
我剛才用bcb試了一下 TIniFile *ini; ini=new TIniFile(ChangeFileExt(Application->ExeName, ".ini")); ini->WriteString("System",ComboBox1->Text," "); 這樣子是會正常動作的 所以應該是沒有問題
vclphi
一般會員


發表:28
回覆:39
積分:13
註冊:2003-03-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-05-29 11:32:24 IP:218.5.xxx.xxx 未訂閱
问题我自己解决了。 procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var filename:string; inifile:TINIFILE; i:integer; breedno:tstringlist; begin if key=VK_Return then begin //取得文件路径 filename:=ExtractFilePath(paramstr(0)) 'stat1.ini'; inifile:=TInifile.Create(filename); breedno:=tstringlist.create; inifile.ReadSection('System',breedno); for i:=0 to breedno.Count-1 do inifile.DeleteKey('System',breedno.Strings[i]); inifile.WriteString ('System',combobox1.Text,' '); for i:=0 to 8 do begin inifile.WriteString('System',breedno.Strings[i],' '); combobox1.items.add(breedno.Strings[i]); end; inifile.UpdateFile ; inifile.Free ; listTitle1; end; end;
系統時間:2024-05-04 19:03:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!