1

I connect TFDQuery with TStringGrid in live binding in delphi firemonkey apps.

I tried to use filter in TFDQuery based on Editbox for searching purpose, and it's work just fine.

but, whenever I clear the Editbox, one of my row in TStringGrid would show "(bcd)" as it's value like the pict below.

what am I doing wrong ? how can I fix it ?

enter image description here

Edit :

  1. Im using mySql database with firedac tfdconnection + tfdquery
  2. the datatype of the column is AnsiString & FmtBCS(32,0)
  3. Im using live binding feature in delphi.
  4. my filter code

    with MainQuery do begin Filtered := False; OnFilterRecord := nil; Filter := FilterValue; Filtered := True; end;

  5. I Insert to the table with TFDConnection.execSQL

the "(BCD)" part always change on the selected Row as the pict below.

EDIT 2: To Reproduce my error, you can :

  1. add TStringGrid.
  2. Add Editbox.
  3. add tfdconnection
  4. add tfdquery
  5. use live binding from tfdquery to tstringgrid.
  6. add query to tfdquery.sql.text that using SUM() in mysql. Example : "select id, sum(stock) as total_stock from stocks"
  7. activate that tfdquery
  8. add onkeyup event on editbox.
  9. add this code :

FilterValue:= 'garmines_id LIKE ''/' +Edit1.Text+'%'' ESCAPE ''/'' '; with FDQuery1 do begin
Filtered:= false;
OnFilterRecord := nil;
Filter := FilterValue;
Filtered := True;
end;

  1. run
  2. try to type something on editbox to make sure filter works fine.
  3. clear editbox, then the "(BCD)" is show on the selected row.

I reproduce this error. this is the SS : enter image description here

punk73
  • 378
  • 2
  • 12
  • 1
    There is insufficient information in your q for readers to be able to reproduce this problem. Please ad to your q a) the type of DB your data is stored in, b) the data-type of the columns in the db table, c) the declared field types in your code and d) your code which constructs the filter. Also, pls include some `InsertRecord` statements which insert the data shown into the db table. – MartynA Jan 05 '18 at 09:48
  • @MartynA Already edited my question. – punk73 Jan 05 '18 at 10:32
  • 1
    Unfortunately, you did not include the InsertRecord statement I mentioned. Anyway, I cannot reproduce your problem on a table with a single FmtBCD field, so am reluctamt to spend any more time on it. You need an MCVE - see https://stackoverflow.com/help/mcve – MartynA Jan 05 '18 at 11:10
  • sorry, newbie. @MartynA please refer to second edit for clarify. – punk73 Jan 06 '18 at 02:23
  • 2
    You still haven't provided an MCVE (note the Complete and Verifiable), your q is still missing details such as the DDL defintion of your table in the database, sample data and I don't see how any of the data rows you've shown would ever match your filter expression. So, I'm voting to close this q. – MartynA Jan 06 '18 at 11:10

2 Answers2

0

Well, I still don't know what exactly causing this problem but I found the work around solution that avoid this problem appears.

you need to set TStringGrid.selected value to -1 before refreshing the TFDQuery. so the code become :

FilterValue:= 'garmines_id LIKE ''/' +Edit1.Text+'%'' ESCAPE ''/'' ';

StringGrid1.selected := -1;

with FDQuery1 do  begin
  Filtered:= false;
  OnFilterRecord := nil;
  Filter := FilterValue;
  Filtered := True;
end;

I suspect that the cause of this problem is data type that come from mysql sum() method namely FmtBCD(32)

punk73
  • 378
  • 2
  • 12
0

Go to DataMapping Rules (firedac connection) Mark ignore inherited rules create 2 new rules

rule1: source: dtBCD / target datatype: dtDouble / all min: 0 / all max: 100 rule2: source: dtfmtbcd / target datatype: dtDouble / all min: 0 / all max: 100

click ok. now the fields will be dtDouble, and are compatible with tgrid