delphidelphi-xe2tcheckbox

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.

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'.

Any help would be much appreciated.

Thanks,


Solution

  • If the field 'active' holds a string you should write:

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

    Right now you are filtering on the boolean value True. Also, why don't you use a boolean / bit field for this Active field?