Board index » delphi » Partial match anywhere Filter in the Filter property

Partial match anywhere Filter in the Filter property

Hello,

I know that by using an asterisk (*) at the end of a value in the Filter
property of a table will give me a partial comparte for that filter and
matches will be "partial match at beginning" type.  Is there a way I can do
a "partial match anywhere" type filter in the filter property of a table?  I
tried wrapping the Filter value with * on both sides but that did not work.
I'm trying to avoid an expression filter at all costs.

Thanks,

David.

 

Re:Partial match anywhere Filter in the Filter property


You can try putting the code into the OnFilter Event handler -

procedure TDataModule.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  Accept := (Pos(UpperCase(FFilterValue),
UpperCase(Table1StringToSearch.Value)) > 0);
end;

BUT . . . test this idea out with some time benchmarks. I've read articles
that show that using the OnFilter event can be slower than the Filter
property by a significant proportion.

Good luck.

John Elrick
j...@improgrammer.com

Quote
David K <david_kee...@hotmail.com> wrote in message

news:7k7qb1$m4b8@forums.borland.com...
Quote
> Hello,

> I know that by using an asterisk (*) at the end of a value in the Filter
> property of a table will give me a partial comparte for that filter and
> matches will be "partial match at beginning" type.  Is there a way I can
do
> a "partial match anywhere" type filter in the filter property of a table?
I
> tried wrapping the Filter value with * on both sides but that did not
work.
> I'm trying to avoid an expression filter at all costs.

> Thanks,

> David.

Re:Partial match anywhere Filter in the Filter property


Yes, you are right about decreased performance.  Hopefully my terms were
correct...since this is what I call an expression filter (i.e. Coding an
onfilter event) since every record has to be compared through an event.

I was looking for a way to make this happen in the Filter property, but I
don't think it will be as simple as wrapping the value with asterisks.

Thanks for the help,

David.

Quote

>BUT . . . test this idea out with some time benchmarks. I've read articles
>that show that using the OnFilter event can be slower than the Filter
>property by a significant proportion.

>Good luck.

>John Elrick
>j...@improgrammer.com

Re:Partial match anywhere Filter in the Filter property


Hi,

Can you use a Query (SQL) for the filtering?
If you can, then use the LIKE statement:

SELECT * FROM Table1
WHERE Field1 LIKE "Adam"

Frank
--------------

Quote
David K wrote:

> Hello,

> I know that by using an asterisk (*) at the end of a value in the Filter
> property of a table will give me a partial comparte for that filter and
> matches will be "partial match at beginning" type.  Is there a way I can do
> a "partial match anywhere" type filter in the filter property of a table?  I
> tried wrapping the Filter value with * on both sides but that did not work.
> I'm trying to avoid an expression filter at all costs.

> Thanks,

> David.

Re:Partial match anywhere Filter in the Filter property


If you use LIKE, you have to use wildcards, such as

WHERE Field1 LIKE "%Adam%"

the % symbols are like * for files, matching 0+ other characters. Access
actually uses the "*" character, but standard SQL doesn't.

That's right, isn't it guys?

Graham Stratford

Quote
Frank Fortino wrote:

> Hi,

> Can you use a Query (SQL) for the filtering?
> If you can, then use the LIKE statement:

> SELECT * FROM Table1
> WHERE Field1 LIKE "Adam"

> Frank
> --------------

> David K wrote:

> > Hello,

> > I know that by using an asterisk (*) at the end of a value in the Filter
> > property of a table will give me a partial comparte for that filter and
> > matches will be "partial match at beginning" type.  Is there a way I can do
> > a "partial match anywhere" type filter in the filter property of a table?  I
> > tried wrapping the Filter value with * on both sides but that did not work.
> > I'm trying to avoid an expression filter at all costs.

> > Thanks,

> > David.

Re:Partial match anywhere Filter in the Filter property


If your DataSet is small enough, there is another way.

If you download RxLib (Version 2.6) there is a control called TMemoryData.
You can load your dataset into the TMemoryData object -
MemoryData1.LoadFromDataSet(Table1, ...) and run the on Filter event from
there.

Since everything resides in memory, the filtering is lightning fast.  I've
tested MemoryData with 100,000 records and it doesn't {*word*99} out.

Only a few lines of code, so it may be worth a shot.

John

Quote
David K <david_kee...@hotmail.com> wrote in message

news:7k9psm$o3c10@forums.borland.com...
Quote
> Yes, you are right about decreased performance.  Hopefully my terms were
> correct...since this is what I call an expression filter (i.e. Coding an
> onfilter event) since every record has to be compared through an event.

> I was looking for a way to make this happen in the Filter property, but I
> don't think it will be as simple as wrapping the value with asterisks.

> Thanks for the help,

> David.

> >BUT . . . test this idea out with some time benchmarks. I've read
articles
> >that show that using the OnFilter event can be slower than the Filter
> >property by a significant proportion.

> >Good luck.

> >John Elrick
> >j...@improgrammer.com

Other Threads