1
votes

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

2
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
@MartynA Already edited my question.punk73
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 stackoverflow.com/help/mcveMartynA
sorry, newbie. @MartynA please refer to second edit for clarify.punk73
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

2 Answers

0
votes

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)

0
votes

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