0

我曾经对过滤器查询使用单个代码,并使用多个 TZquery 进行了尝试,但它不起作用。所有表都包含 client_id 列,我希望代码在 TEdit 上搜索具有客户端 ID 的信息,它适用于单个 TZquery,但不能用于多个。谢谢。

这是我使用的代码:

zquery1.FilterOptions:=[foCaseInsensitive]; 
zquery1.Filtered := Length(Edit1.Text) > 0; 
if zquery1.Filtered then 
  zquery1.Filter := 'client_id like ' + 
       QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
else 
  zquery1.Filter := '';

zquery2.FilterOptions:=[foCaseInsensitive]; 
zquery2.Filtered := Length(Edit1.Text) > 0; 
if zquery2.Filtered then 
  zquery2.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
else 
  zquery2.Filter := '';

zquery3.FilterOptions:=[foCaseInsensitive]; 
zquery3.Filtered := Length(Edit1.Text) > 0; 
if zquery3.Filtered then 
  zquery3.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
else 
  zquery3.Filter := '';

zquery4.FilterOptions:=[foCaseInsensitive]; 
zquery4.Filtered := Length(Edit1.Text) > 0; 
if zquery4.Filtered then 
  zquery4.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
else 
  zquery4.Filter := '';
4

1 回答 1

0

我只在过滤为假时更改过滤条件。所以我会写你的代码如下

zquery1.FilterOptions:=[foCaseInsensitive]; 
zquery1.Filtered := false;
if Length(Edit1.Text) > 0 then
begin
  zquery1.Filter := 'client_id like ' +  QuotedStr(trim(Edit1.Text)) ;
  zquery1.Filtered := true;
end;

zquery2.FilterOptions:=[foCaseInsensitive]; 
zquery2.Filtered := false;
if Length(Edit1.Text) > 0 then
begin
  zquery2.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
  zquery2.Filtered := true;
end;

zquery3.FilterOptions:=[foCaseInsensitive]; 
zquery3.Filtered := false;
if Length(Edit1.Text) > 0 then
begin
  zquery3.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
  zquery3.Filtered := true;
end;

zquery3.FilterOptions:=[foCaseInsensitive]; 
zquery3.Filtered := false;
if Length(Edit1.Text) > 0 then
begin
  zquery3.Filter := 'client_id like ' + QuotedStr('' + Edit1.Text + '') // Zeos- Syntax 
  zquery3.Filtered := true;
end;
于 2013-11-06T05:38:34.327 回答