TTMSFNCDatagrid with filtering per program and casesensitive=false

I tried to search in the DataGrid from a inputfield (editfield).
there are two field i want to search for.
Nachname and vorname.
Normaly ich search only in the Nachname Column.
There are Data like 'Bart', 'Bach',Baldwin'.
The problem is, i want to input only 'b' to search not a 'B'.
But the Datagrid is Casesensitive so cannot find anything if i type 'b'.
This is my program:

procedure TfrmInteressenten.edtSucheChange(Sender: TObject);
var
  Suchbegriff, Nachname, Vorname: string;
  SepPos: Integer;
//  fltr:TTMSFNCDataGridDataFilterData;
begin
  Suchbegriff := Trim(edtSuche.Text);
  GridInteressenten.Filter.Clear;

  if Suchbegriff = '' then
  begin
    GridInteressenten.ApplyFilter;
    Exit;
  end;

  // Prüfen, ob ein Komma enthalten ist
  SepPos := Pos(',', Suchbegriff);
  if SepPos > 0 then
  begin
    // Nachname vor dem Komma
    Nachname := Trim(Copy(Suchbegriff, 1, SepPos - 1));
    // Vorname nach dem Komma
    Vorname := Trim(Copy(Suchbegriff, SepPos + 1, Length(Suchbegriff) -
      SepPos));

    GridInteressenten.Filter.Add(0, gftStartsWith, Nachname).&And(1, gftStartsWith, Vorname);
  end
  else
  begin
    // Nur Nachname suchen
    GridInteressenten.Filter.Add(0, gftStartsWith, Suchbegriff);
  end;

  // Setzen Sie die Filteroptionen, um die Groß-/Kleinschreibung zu ignorieren
//  fltr.CaseSensitive:=False;

  GridInteressenten.ApplyFilter;
end;

The second Try was this:

procedure TfrmInteressenten.edtSucheChange(Sender: TObject);
var
  Suchbegriff, Nachname, Vorname: string;
  SepPos: Integer;
begin
  Suchbegriff := Trim(edtSuche.Text);
  GridInteressenten.Filter.Clear;

  if Suchbegriff = '' then
  begin
    GridInteressenten.ApplyFilter;
    Exit;
  end;

  // Prüfen, ob ein Komma enthalten ist
  SepPos := Pos(',', Suchbegriff);
  if SepPos > 0 then
  begin
    // Nachname vor dem Komma
    Nachname := Trim(Copy(Suchbegriff, 1, SepPos - 1));
    // Vorname nach dem Komma
    Vorname := Trim(Copy(Suchbegriff, SepPos + 1, Length(Suchbegriff) - SepPos));

    // Filter hinzufügen und CaseSensitive auf False setzen
    with GridInteressenten.Filter.Add do
    begin
      Condition := Nachname + '*'; // Bedingung für "StartsWith"
      Column := 0; // Spalte "Nachname"
      CaseSensitive := False;
    end;

    with GridInteressenten.Filter.Add do
    begin
      Condition := Vorname + '*'; // Bedingung für "StartsWith"
      Column := 1; // Spalte "Vorname"
      CaseSensitive := False;
    end;
  end
  else
  begin
    // Nur Nachname suchen
    with GridInteressenten.Filter.Add do
    begin
      Condition := Suchbegriff + '*'; // Bedingung für "StartsWith"
      Column := 0; // Spalte "Nachname"
      CaseSensitive := False;
    end;
  end;

  GridInteressenten.ApplyFilter;
end;

But also this example do not deactivate the casesensitive search.
Only when typing 'B' i could find my Data beginning with B

If you are using filtering connected to a database adapter, the dataset is responsible for handling the case-sensitivity. There should be options to control this.

could you say what option in Firedac i have to set to get a not caseSensitive search.

https://docwiki.embarcadero.com/Libraries/Athens/en/Data.DB.TDataSet.FilterOptions

I set the Query.FilterOptions:=[foCaseInsensitive];

Thanks this works.

1 Like