Delphi - DBGrid does not replace first line content

1

Good morning folks ...

I have a table in a SQLite database with a field of type "integer" to store "boolean" values. This field is linked, in the registration screen, to a DBCheckbox. So in order to check and uncheck the DBCheckbox, I had to write the OnGetText and OnSetText events of the field.

Now I need to show "Yes" and "No" values based on this field in a DBGrid. I wrote the code below on the OnDrawColumnCell event:

procedure TfrmPesquisar.dbgPesquisarDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if Column.Field = dsPesquisar.DataSet.FieldByName('claAtiva') then
  begin
    dbgPesquisar.Canvas.FillRect(Rect);
    if Column.Field.AsString = '0' then
      dbgPesquisar.Canvas.TextOut(Rect.Left+10,Rect.Top+3,'Não')
    else
      dbgPesquisar.Canvas.TextOut(Rect.Left+10,Rect.Top+3,'Sim');
  end;
end;

However, only the first line is incorrectly displaying the value to be replaced (No) and the actual value (0 - zero), as shown below:

Has anyone ever had something similar or do you know the solution?

Thank you very much for the help.

    
asked by anonymous 20.02.2018 / 17:02

2 answers

1

I suggest then move to the SQL query itself resolve:

something like:

CASE Ativa
 WHEN '0' THEN
 'Não'
 ELSE
 'Sim'
 END Ativa

In this way the result is ready to be displayed.

    
21.02.2018 / 13:52
0

I do not know if it works on Delphi for Android more on Desktop I use OnGetText

Example

if QryPesquisaclaAtiva.AsString = '0' 
then Text:='Não'
else Text:='Sim';
    
20.02.2018 / 19:22