Fulltext Filter / Locate: find first / all matching row (s)

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Fulltext Filter / Locate: find first / all matching row (s)

Post by dschuch » Tue 05 Mar 2013 07:11

Hi,

i wonder if there is a way to filter over all columns or - at least to locate the first row matching a specific String (column doesnt matter). (... and locate next if so)

We want to give the user the possibility to say "Search" and after, he is getting the rows, matching his search cirteria in some column.

Daniel.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Fulltext Filter / Locate: find first / all matching row (s)

Post by DemetrionQ » Thu 07 Mar 2013 13:18

Hello.

The basic TDataSet class, which is the basis for TPgQuery and TPgTable, has no function for such search. But you can create it by yourself. For example, the following code searches by all fields and goes to a record next to the beginning, that contains a field with content containing the text of SearchText variable:

Code: Select all

function SearchInDatSet(DataSet:TDataSet; SearchText:string):boolean;
  var i:integer;
begin
  result:=false;
  DataSet.First;
  while not DataSet.Eof do begin
    for i := 0 to DataSet.Fields.Count - 1 do begin
      result:=ContainsText(DataSet.Fields.Text,SearchText); 
      //ContainsText - a function from the StrUtils module
      if result then
        exit; //if a record is found, end search by exiting the function
    end;
    DataSet.Next;
  end;
end;

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Re: Fulltext Filter / Locate: find first / all matching row (s)

Post by dschuch » Wed 20 Mar 2013 22:56

Hy, thanks for your awnser.

As descriped in my second post, running through all records is a bad design because all events are fired. (AfterScroll, VCL-Evens and so on)

We solved the Problem with the OnFilterRecord - event. Thats working fine. We implemented our FullTextFilter there.

Post Reply