数据集中某字段包含某字符串的判断
var
codeStr: String;
i:integer;
Begin
if (Edit1.Text<>'') then
begin
i:=0;
with WMG_DM.cha_adoquery do
begin
close;
sql.Clear;
sql.Add('SELECT cname FROM chaee');
open;
with WMG_DM.cha_adoquery do
begin
first;
while not Eof do
begin
if pos(trim(edit5.text),fieldbyname('cname').AsString)>0 then
{想实现表chaee中字段cname的每个记录与trim(edit5.text)进行比较,如果包含trim(edit5.text)字符串,则i+1}
begin
//>0为包含子串,=0为不包含子串
i:=i+1;
edit7.text:=inttostr(i);
next;
end;
if pos(trim(edit5.text),fieldbyname('cname').AsString)=0 then
begin
//>0为包含子串,=0为不包含子串
showmessage('字段cname中不包含edit5.text所显示的字符串,请核查。');
close;
end;
end;
end;
end;
end;