unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function gettext(index:integer):string;
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
combobox1.Text:='';
combobox1.Items.Add('中国');
combobox1.Items.Add('美国');
combobox1.Items.Add('法国');
combobox1.Items.Add('英国');
button1.Caption:='添加';
end;procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
for i:=0 to combobox1.Items.Count do
begin
if edit1.Text=gettext(i) then
begin
exit;
end;
end;
combobox1.Items.Add(edit1.Text);
end;function TForm1.gettext(index: integer): string;
begin
combobox1.ItemIndex:=index;
result:=combobox1.Text;
end;end.
注:
combobox1 已有选项:
中国
美国
法国
英国向其添加"中国",不响应
结果仍然是:
中国
美国
法国
英国向其添加"德国",响应
结果是:
中国
美国
法国
英国
德国我的做法可以实现功能
但是当I很大时,循环次数就很大,请大虾指点更合理的做法,谢了.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function gettext(index:integer):string;
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
combobox1.Text:='';
combobox1.Items.Add('中国');
combobox1.Items.Add('美国');
combobox1.Items.Add('法国');
combobox1.Items.Add('英国');
button1.Caption:='添加';
end;procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
for i:=0 to combobox1.Items.Count do
begin
if edit1.Text=gettext(i) then
begin
exit;
end;
end;
combobox1.Items.Add(edit1.Text);
end;function TForm1.gettext(index: integer): string;
begin
combobox1.ItemIndex:=index;
result:=combobox1.Text;
end;end.
注:
combobox1 已有选项:
中国
美国
法国
英国向其添加"中国",不响应
结果仍然是:
中国
美国
法国
英国向其添加"德国",响应
结果是:
中国
美国
法国
英国
德国我的做法可以实现功能
但是当I很大时,循环次数就很大,请大虾指点更合理的做法,谢了.
解决方案 »
- 线程释放的问题
- 在代码中如何捕捉存储过程中定义的错误?
- 请问如何取消提交的信息!急!!!
- 我新建一个工程。添加一个窗体运行可以,编译不成功
- TFormatRange记录类型的问题,解决立结!!
- 关于delphi组件,简单问题,不过比较急!不知道今天能不能解决,帮忙啊
- 问题的关键在哪里:发邮件程序?
- 点击treeview一个子结点后在数据库中查询,第一次点击正确,再点击其他时就出错,为什么?代码是...
- if dm.ClientDataSet_c.state in [dsedit,dsinsert] then这句错在哪?
- 请教大虾们:如何检测自己的程序消耗了多少系统资源?(内详)
- 如何获得ActiveForm所在网页中的IP地址?兄弟请进。
- 关于ADOQUERY的问题
ComBoBox1.Items.Add(Edit1.Text);