简体   繁体   English

TCheckBox通过字段过滤数据集

[英]TCheckBox to filter dataset by a field

I'm trying to filter a dataset by one field when ticking a checkbox, the following is code what I have put together and thought was correct but it doesn't appear to be working, it brings back 0 records. 勾选复选框时,我试图按一个字段过滤数据集,以下是我整理并认为正确的代码,但它似乎没有用,它带回了0条记录。

procedure TfrmCustomers.cbClick(Sender: TObject);
if cbActive.Checked = True then
with dmod.cds do
begin
  DisableControls;
  try
    Filtered := False;
    FilterOptions := [foCaseInsensitive,foNoPartialCompare];
    Filter := ('active LIKE true');
    Filtered := True;
  finally
    EnableControls;
  end;
end;
end;

The name of the field in the dataset is called 'active' and it stores a string of either 'true' or 'false'. 数据集中的字段名称称为“活动”,它存储字符串“ true”或“ false”。

Any help would be much appreciated. 任何帮助将非常感激。

Thanks, 谢谢,

If the field 'active' holds a string you should write: 如果字段“ active”包含字符串,则应输入:

Filter := ('active = ''true''');

Right now you are filtering on the boolean value True. 现在,您正在过滤布尔值True。 Also, why don't you use a boolean / bit field for this Active field? 另外,为什么不为此活动字段使用布尔值/位字段呢?

像这样改变过滤线

Filter := ('active = ''true''');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM