Procedure SearchByPYIndexStr(Const SourceStrs:TStringList;Const PYIndexStr:string; Var Box:TListBox);
label NotFound;
var
i, j :integer;
hzchar :string;
begin
box.Items.Clear;
for i:=0 to SourceStrs.Count-1 do
begin
for j:=1 to Length(PYIndexStr) do
begin
if Length(SourceStrs[i])=0 then goto NotFound;
hzchar:=SourceStrs[i][j];
if PYIndexStr[j] <> hzchar
then goto NotFound;
end;
box.Items.Addobject(SourceStrs[i],sourcestrs.Objects[i]);
NotFound:
end;
end;
label NotFound;
var
i, j :integer;
hzchar :string;
begin
box.Items.Clear;
for i:=0 to SourceStrs.Count-1 do
begin
for j:=1 to Length(PYIndexStr) do
begin
if Length(SourceStrs[i])=0 then goto NotFound;
hzchar:=SourceStrs[i][j];
if PYIndexStr[j] <> hzchar
then goto NotFound;
end;
box.Items.Addobject(SourceStrs[i],sourcestrs.Objects[i]);
NotFound:
end;
end;
改为box:tcombobox即可。
var sXing:string;
begin
sXing:=Trim(combobox1.text);
Query1.close;
query1.sql.text:='Select Name from TableName where Name like ''%'+sXing+'%''';
Query1.Open;
Query1.first;
Combobox1.items.clear;
while not Query1.eof do
begin
Combobox1.items.add(Query1.fieldbyname('Name').asstring);
Query1.next;
end;
Query1.close;
end;这样就行了;有的Combobox1具有过滤功能,你可以找找看
a,b:string;//b保存combobox1.text,
beginb:=combobox1.text;with table1 do
begin
open;
first;
repeat
a:=fieldbyname('name').asstring;//取姓名赋给a
setlength(a,2);//由姓名中取姓
if a=b then//如果姓等于combobox1.text
combobox1.items.add(rightstr(a,length(a)-2));//取姓名中的名
next;
unitl eof;
end;
var
a,b:string;//b保存combobox1.text,
begincombobox1.items.clear;//加了一句
b:=combobox1.text;with table1 do
begin
open;
first;
repeat
a:=fieldbyname('name').asstring;//取姓名赋给a
setlength(a,2);//由姓名中取姓
if a=b then//如果姓等于combobox1.text
combobox1.items.add(rightstr(a,length(a)-2));//取姓名中的名
next;
unitl eof;
end;
end;//加的第二句
var
a,b:string;//b保存combobox1.text,
begincombobox1.items.clear;//加了一句
b:=combobox1.text;with table1 do
begin
open;
first;
repeat
a:=fieldbyname('name').asstring;//取姓名赋给a
setlength(a,2);//由姓名中取姓
if a=b then//如果姓等于combobox1.text
combobox1.items.add(rightstr(fieldbyname('name').asstring,length(a)-2));//取姓名中的名,最后修改的语句
next;
unitl eof;
end;
end;//加的第二句