0

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,

Sharpie
  • 373
  • 2
  • 15
  • 34

2 Answers2

3

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?

Birger
  • 4,343
  • 21
  • 35
0

Change filter line like this

Filter := ('active = ''true''');
sddk
  • 1,115
  • 1
  • 10
  • 20
  • 1
    No. `LIKE` is slower, and is meant for use when you're using a wild card. If you're doing a match to specific content, use `=` instead. – Ken White Jul 22 '15 at 18:04