Grid filtering error

Dear Sirs,

I am trying to filter grid by using TFilter.

My code is:

      with sgMain do begin
            OnSelectCell := nil;
            FilterActive := false;
            Filter.Clear ();

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 2;
                        CaseSensitive := false;
                        Operation := foAND;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 4;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 11;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 13;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 16;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 6;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 8;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

                  with Filter.Add do begin
                        Condition := '' + '"' + edSearchString.Text + '"' + '';
                        Column := 10;
                        CaseSensitive := false;
                        Operation := foOR;
                  end;

            FilterActive := true;

            OnSelectCell := OnSelectCellEvent;
            Select ();
      end;

And sometimes filter makes duplicates rows in grid. I don't know why and how it is happen. Just two or three similar rows after filtering.

Maybe I use Operation (foAND, foOR) in wrong way. Could you please help me?

Thanks.

Try to change your code to:

 

      with sgMain do begin

            OnSelectCell := nil;

            FilterActive := false;

            Filter.Clear ();

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 2;

                        CaseSensitive := false;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 4;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 11;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 13;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 16;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 6;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 8;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

                  with Filter.Add do begin

                        Condition := "*" + """ + edSearchString.Text + """ + "*";

                        Column := 10;

                        CaseSensitive := false;

                        Operation := foOR;

                  end;

 

            FilterActive := true;

 

            OnSelectCell := OnSelectCellEvent;

            Select ();

      end;

 

The first filter condition doesn't need a logical operation as there is no preceding filter condition.