* * *

Author Topic: BufDataset | filter with and/or  (Read 213 times)

cpalx

  • Hero Member
  • *****
  • Posts: 586
BufDataset | filter with and/or
« on: November 03, 2018, 09:50:21 pm »
hello,

how could i do something like this?

Code: Pascal  [Select]
  1. with bufdataset1 do begin
  2.    filtered:= false;
  3.    filter:= format(  'field1= ''%s''  or field2= ''%s:0'' ', [edit1.text] );
  4.    filtered:=true;
  5. end;
« Last Edit: November 03, 2018, 10:03:02 pm by cpalx »

lucamar

  • Sr. Member
  • ****
  • Posts: 316
Re: BufDataset | filter with and/or
« Reply #1 on: November 03, 2018, 09:56:44 pm »
I don't know the answer but about the Format ... shouldn't it be like this:

Format( 'field1= ''%s''  or field2= ''%s:0'' ', [edit1.text] );

???
Been there, done that ... barely kept the timelines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/fpc 3.0.4 - Ubuntu 10, Kubuntu 14, Windows XP SP3 (Home & Prof.) and various DOS incarnations.

cpalx

  • Hero Member
  • *****
  • Posts: 586
Re: BufDataset | filter with and/or
« Reply #2 on: November 03, 2018, 10:02:05 pm »
@lucamar you are right about the format. I will edit my post.

the problem goes on

wp

  • Hero Member
  • *****
  • Posts: 5034
Re: BufDataset | filter with and/or
« Reply #3 on: November 03, 2018, 10:05:28 pm »
There are two format parameters in the format string, but there is only one string. Either you apply a second parameter
Code: Pascal  [Select]
  1. Format('field1= ''%s'' or field2=''%s''', [Edit1.Text, Edit2.Text]);
or if there is only one parameter needed twice you can use an index in the format string as proposed by lucamar; but use the correct syntax:
Code: Pascal  [Select]
  1. Format('field1= ''%0:s'' or field2=''%0:s''', [Edit1.Text]);
See: https://www.freepascal.org/docs-html/rtl/sysutils/format.html
« Last Edit: November 03, 2018, 10:07:03 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

lucamar

  • Sr. Member
  • ****
  • Posts: 316
Re: BufDataset | filter with and/or
« Reply #4 on: November 03, 2018, 10:36:08 pm »
[...] but use the correct syntax:
Code: Pascal  [Select]
  1. Format('field1= ''%0:s'' or field2=''%0:s''', [Edit1.Text]);

Oops! Sorry, I did, indeed, invert the expression. I never remember all the nuances of Format :-[

Re. the expression itself, I have been looking into the sources and found that the filter is parsed in unit dbf_prscore. Its header apparently points to some info:
Code: Pascal  [Select]
  1. unit dbf_prscore;
  2.  
  3. {--------------------------------------------------------------
  4. | TCustomExpressionParser
  5. |
  6. | - contains core expression parser
  7. |
  8. | This code is based on code from:
  9. |
  10. | Original author: Egbert van Nes
  11. | With contributions of: John Bultena and Ralf Junker
  12. | Homepage: http://www.slm.wau.nl/wkao/parseexpr.html
  13. |
  14. | see also: http://www.datalog.ro/delphi/parser.html
  15. |   (Renate Schaaf (schaaf at math.usu.edu), 1993
  16. |    Alin Flaider (aflaidar at datalog.ro), 1996
  17. |    Version 9-10: Stefan Hoffmeister, 1996-1997)
  18. |
  19. |---------------------------------------------------------------}
  20.  
  21. interface
  22.   [. . .]
  23.  
Been there, done that ... barely kept the timelines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/fpc 3.0.4 - Ubuntu 10, Kubuntu 14, Windows XP SP3 (Home & Prof.) and various DOS incarnations.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus