線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1369
推到 Plurk!
推到 Facebook!

如何用dbedit的text去刪掉combobox內的item

答題得分者是:hagar
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-02 12:45:41 IP:210.201.xxx.xxx 未訂閱
小弟想在dbedit輸入一些text 再利用一個button按一下後會 把combobox 內一樣內容的items 刪掉不知要怎麼作才好 例如 在dbedit打入 你好 按一下button combobox內所有是 你好 的items 都會刪除 aric
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-03-02 16:32:01 IP:202.39.xxx.xxx 未訂閱
procedure TForm1.Button1Click(Sender: TObject);
var idx: integer;
begin
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);
  if idx <> -1 then
    ComboBox1.Items.Delete(idx);
end;
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-02 18:01:14 IP:210.201.xxx.xxx 未訂閱
引言:
procedure TForm1.Button1Click(Sender: TObject);
var idx: integer;
begin
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);
  if idx <> -1 then
    ComboBox1.Items.Delete(idx);
end;
在系統未結束前是刪了 但再進入時還是會存在 有沒有能真的刪掉的方法?
aric
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-03-02 18:16:28 IP:202.39.xxx.xxx 未訂閱
引言: 在系統未結束前是刪了 但再進入時還是會存在 有沒有能真的刪掉的方法?
那跟你問如何動態增加 Item 的那篇一樣 參照 ccchen 前輩的說法來做.
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-03-04 10:35:49 IP:210.201.xxx.xxx 未訂閱
引言:
引言: 在系統未結束前是刪了 但再進入時還是會存在 有沒有能真的刪掉的方法?
那跟你問如何動態增加 Item 的那篇一樣 參照 ccchen 前輩的說法來做.
抱歉我試一些方法都沒有用 有沒有更詳細的說明? aric
danny
版主


發表:100
回覆:522
積分:595
註冊:2002-03-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-03-04 15:45:19 IP:218.187.xxx.xxx 未訂閱
引言:
引言:
引言: 在系統未結束前是刪了 但再進入時還是會存在 有沒有能真的刪掉的方法?
那跟你問如何動態增加 Item 的那篇一樣 參照 ccchen 前輩的說法來做.
抱歉我試一些方法都沒有用 有沒有更詳細的說明?
有點混哦 ! 問題也沒有說清楚. 我您可能 ComboBox1 在 Design Time 時已經有一些內定值了. 所以在 OnFormCreate 及 OnButtonClick 中要呼叫以下 procedure
procedure TForm1.DeleteComboBoxItem;
var idx: integer;
begin  
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);  
  if idx <> -1 then    
    ComboBox1.Items.Delete(idx);
end;
------
將問題盡快結案也是一種禮貌!
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-03-05 01:47:21 IP:61.219.xxx.xxx 未訂閱
         [/quote]    有點混哦 ! 問題也沒有說清楚.    我您可能 ComboBox1 在 Design Time 時已經有一些內定值了. 所以在 OnFormCreate 及 OnButtonClick 中要呼叫以下 procedure
procedure TForm1.DeleteComboBoxItem;
var idx: integer;
begin  
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);  
  if idx <> -1 then    
    ComboBox1.Items.Delete(idx);
end;
[/quote] 我不太曉得應如何宣告及呼叫 procedure Tform1.deletecomboboxItem; 所以我直接在form1的oncreate及button1的onclick 都打入以下程式碼 var idx: integer; begin idx := ComboBox1.Items.IndexOf(DBEdit1.Text); if idx <> -1 then ComboBox1.Items.Delete(idx); 但在TForm1.formcreate(sender:Tobject); 執行有錯誤訊息出現->(~89****) 能否詳述如何宣告及呼叫 procedure Tform1.deletecomboboxItem; aric
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-03-05 09:40:44 IP:202.39.xxx.xxx 未訂閱
假設將 ComboBox1 的 Items 存在 C:\ComboBox1Item.Txt 1.在 FormCreate 做載入 Item 的動作
procedure TForm1.FormCreate(Sender: TObject);
begin
  if FileExists('C:\ComboBox1Item.Txt') then
    ComboBox1.Items.LoadFromFile('C:\ComboBox1Item.Txt');
end;
2.Button1 做比對 DBEdit1.Text 來刪除 Item 的動作:
procedure TForm1.Button1Click(Sender: TObject);
var idx: integer;
begin
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);
  if idx <> -1 then
    ComboBox1.Items.Delete(idx);
end;
3.在 FormClose 的時候, 將 ComboBox1 的 Item 存入 C:\ComboBox1Item.Txt
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ComboBox1.Items.SaveToFile('C:\ComboBox1Item.Txt');
end;
--- Have you ever wondered what it would be like?
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-03-06 00:12:10 IP:61.219.xxx.xxx 未訂閱
引言: 假設將 ComboBox1 的 Items 存在 C:\ComboBox1Item.Txt 1.在 FormCreate 做載入 Item 的動作
procedure TForm1.FormCreate(Sender: TObject);
begin
  if FileExists('C:\ComboBox1Item.Txt') then
    ComboBox1.Items.LoadFromFile('C:\ComboBox1Item.Txt');
end;
2.Button1 做比對 DBEdit1.Text 來刪除 Item 的動作:
procedure TForm1.Button1Click(Sender: TObject);
var idx: integer;
begin
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);
  if idx <> -1 then
    ComboBox1.Items.Delete(idx);
end;
3.在 FormClose 的時候, 將 ComboBox1 的 Item 存入 C:\ComboBox1Item.Txt
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ComboBox1.Items.SaveToFile('C:\ComboBox1Item.Txt');
end;
--- Have you ever wondered what it would be like?
有了滿意的答覆真是謝謝大家 aric
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-03-06 00:17:47 IP:61.219.xxx.xxx 未訂閱
引言: 假設將 ComboBox1 的 Items 存在 C:\ComboBox1Item.Txt 1.在 FormCreate 做載入 Item 的動作
procedure TForm1.FormCreate(Sender: TObject);
begin
  if FileExists('C:\ComboBox1Item.Txt') then
    ComboBox1.Items.LoadFromFile('C:\ComboBox1Item.Txt');
end;
2.Button1 做比對 DBEdit1.Text 來刪除 Item 的動作:
procedure TForm1.Button1Click(Sender: TObject);
var idx: integer;
begin
  idx := ComboBox1.Items.IndexOf(DBEdit1.Text);
  if idx <> -1 then
    ComboBox1.Items.Delete(idx);
end;
3.在 FormClose 的時候, 將 ComboBox1 的 Item 存入 C:\ComboBox1Item.Txt
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ComboBox1.Items.SaveToFile('C:\ComboBox1Item.Txt');
end;
--- Have you ever wondered what it would be like?
有了滿意的答覆真是謝謝大家 aric 發表人 - huangeider 於 2003/03/20 14:42:20
系統時間:2024-05-04 23:14:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!