Search code examples
delphifiredactstringgrid

TStringGrid show (bcd) in delphi live binding


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


Solution

  • 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)