Recent

Author Topic: [SOLVED] TBufDataset filtering - problem with negative values  (Read 3509 times)

axline

  • New Member
  • *
  • Posts: 14
Hello, Lazarus community!
Have been reading this forum for quite a while. Seems like it's time to start writing...

I've got a problem with TBufDataset filtering. If filter looks like 'Field1=15.0 and Filed2=5.0' everything works like a charm. But as soon as any of the values become negative (for example, 'Field1=-15.0 and Filed2=5.0' my project rises an exception 'Index based on unknown field "-"'.

I've found out just one solution - to pass the filter string as QuotedStr(Filter). But it slows the program dramatically. I'm using Lazarus 1.2.0 with fpc 2.6.1 from the latest stable release. Does anyone know anything about a possible solution?
« Last Edit: April 20, 2014, 01:31:19 pm by axline »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TBufDataset filtering - problem with negative values
« Reply #1 on: April 19, 2014, 07:12:22 pm »
Does anyone know anything about a possible solution?
Hi and welcome to Lazarus/FreePascal. I believe this is a problem with the expression parser. Simply replace your expression with an equal one:
Quote
  Field1=0-15.0 and Filed2=5.0

axline

  • New Member
  • *
  • Posts: 14
Re: TBufDataset filtering - problem with negative values
« Reply #2 on: April 20, 2014, 09:15:19 am »
Hi and welcome to Lazarus/FreePascal. I believe this is a problem with the expression parser. Simply replace your expression with an equal one:
 Field1=0-15.0 and Filed2=5.0

thank you, engkin! Unfortunately this solution doesn't work in my case.

Code: [Select]
    nctslatloncds.Filtered:=false; //remove old filter
      if ncLat_arr[lati]>=0 then f_str:='axis='  +Floattostr(ncLat_arr[lati])+' and mn='+inttostr(mni); // if axis value is positive
      if ncLat_arr[lati] <0  then f_str:='axis=0'+Floattostr(ncLat_arr[lati])+' and mn='+inttostr(mni); // if axis value is negative
    nctslatloncds.Filter:=f_str; //set filter
    nctslatloncds.Filtered:=true; //apply filtering

This code runs fine while values of 'axis' are positive. When procedure hits the first negative value it applies filtering, but the second negative value rises an "External: SIGSEGV" error. Still, if I use

Code: [Select]
      if ncLat_arr[lati] <0  then f_str:=QuotedStr('axis='+Floattostr(ncLat_arr[lati])+' and mn='+inttostr(mni)); // if axis value is negative

procedure works ok, but extremely slow. Have tried different 'wraps' around the filter string - no success :(

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TBufDataset filtering - problem with negative values
« Reply #3 on: April 20, 2014, 09:43:24 am »
The expression parser has several limitations and bugs that remain to be fixed. So there are various scenarios which currently give rise either to exceptions, or silent acceptance of filter expressions which are not then applied. You should raise a bug report on Mantis to keep these issues in front of the developers (and add a patch if you are able).

axline

  • New Member
  • *
  • Posts: 14
Re: TBufDataset filtering - problem with negative values
« Reply #4 on: April 20, 2014, 11:37:29 am »
Thank you, howardpc! Have just submitted a bug report on this issue.

axline

  • New Member
  • *
  • Posts: 14
Re: TBufDataset filtering - problem with negative values
« Reply #5 on: April 20, 2014, 01:30:44 pm »
The issue was, in fact, related with the old FPC 2.6.x branch. I've downloaded the latest FPC trunk (27605 currently) and can now confirm - the problem's gone, everything works just fine. So the solution is simple - to upgrade the compiler to the latest version.

 

TinyPortal © 2005-2018