Board index » delphi » Filter problems

Filter problems

I am trying to filter a dataset by using a variation of the
following:

DayStart.Filter:='ShowDate>='+'''+sDate+'''+
              ' OR ShowDay='+'''+sDow+'''+
              'OR ShowMonthDay='''+INttoStr(nDom)+''';

This does not substitute the values for sDate or sDow but takes
them literally.

I have managed to substitute them but not with quotes so the
filter is invalid.
Pat Bell

 

Re:Filter problems


I grabbed this from another posted message.
I think it shows what you need.
  Table1.Filter := format('Company = %s AND City = %s', [
            QuotedStr(Table1.FieldByName('Company').AsString),
            QuotedStr(Table1.FieldByName('City').AsString)]);
  Table1.Filtered := True;

Quote
P.S.Bell <p...@PatBell.demon.co.uk> wrote in message

news:VA.00000218.013e3482@dell...
Quote
> I am trying to filter a dataset by using a variation of the
> following:

> DayStart.Filter:='ShowDate>='+'''+sDate+'''+
>               ' OR ShowDay='+'''+sDow+'''+
>               'OR ShowMonthDay='''+INttoStr(nDom)+''';

> This does not substitute the values for sDate or sDow but takes
> them literally.

> I have managed to substitute them but not with quotes so the
> filter is invalid.
> Pat Bell

Re:Filter problems


You appear to have the variable names in quotes. That is why they are
treated as literals.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Re:Filter problems


Quote
>DayStart.Filter:='ShowDate>='+'''+sDate+'''+
>              ' OR ShowDay='+'''+sDow+'''+
>              'OR ShowMonthDay='''+INttoStr(nDom)+''';

>This does not substitute the values for sDate or sDow but takes
>them literally.

try this

DayStart.Filter:='ShowDate>='+quotesStr(sDate)+
              ' OR ShowDay='+quotedStr(sDow)+
              'OR ShowMonthDay='+quotedStr(INttoStr(nDom));

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads