procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
begin
str:=edit1.Text;
if listbox1.Items.IndexOf(str)=-1 then
listbox1.Items.Add(str);
end;
var
str:string;
begin
str:=edit1.Text;
if listbox1.Items.IndexOf(str)=-1 then
listbox1.Items.Add(str);
end;
为了完美起见,
可以
if
...
else
...
var
str:string;
begin
str:=trim(edit1.Text);//去除左右的空字符,这样更好
if listbox1.Items.IndexOf(str)=-1 then
listbox1.Items.Add(str);
end;