combobox的items是一个Tstrings类型,它有一个方法是indexof ,是一个虚态方法,实现过程如下: function IndexOf(const S: string): Integer; begin for Result := 0 to GetCount - 1 do if CompareStrings(Get(Result), S) = 0 then Exit; Result := -1; end; 你可以对此进行修改, 如:Procedure deleteNotSelectindex(const S: string); var Count:integer begin with ComboBox1 do begin for Count:= 0 to ComboBox1.items.GetCount - 1 do if CompareStrings(Copy(ComboBox1.items.Get(Result),1,1), Copy(S,1,1)) = 0 then ComboBox1.items.delete(Count); end; end; 在进行这个操作之前,先把combobox的items做一个副本,以便回复!
function IndexOf(const S: string): Integer;
begin
for Result := 0 to GetCount - 1 do
if CompareStrings(Get(Result), S) = 0 then Exit;
Result := -1;
end;
你可以对此进行修改, 如:Procedure deleteNotSelectindex(const S: string);
var
Count:integer
begin
with ComboBox1 do
begin
for Count:= 0 to ComboBox1.items.GetCount - 1 do
if CompareStrings(Copy(ComboBox1.items.Get(Result),1,1), Copy(S,1,1)) = 0 then
ComboBox1.items.delete(Count);
end;
end;
在进行这个操作之前,先把combobox的items做一个副本,以便回复!
用combobox.text=''
好像不行