title: Delphi FDQuery to Json
body: <p>I'm trying to convert the result of my Sqlite query into a Json, 
  to use the same procedures I use with remote binding to Sql Server by php.</p>
  
  <p>The code works, but do you think it's a better solution?</p>
  
  <p>Anyone there do that?</p>
  
  <pre><code>function TLogin.RetornaRegistros(query:String): String;
  var
    FDQuery : TFDQuery;
    field_name,nomeDaColuna,valorDaColuna : String;
    I: Integer;
  begin
      FDQuery := TFDQuery.Create(nil);
      try
        FDQuery.Connection := FDConnection1;
        FDQuery.SQL.Text := query;
        FDQuery.Active := True;
        FDQuery.First;
  
        result := '[';
        while (not FDQuery.EOF) do
        begin
  
          result := result+'{';
          for I := 0 to FDQuery.FieldDefs.Count-1 do
          begin
            nomeDaColuna  := FDQuery.FieldDefs[I].Name;
            valorDaColuna := FDQuery.FieldByName(nomeDaColuna).AsString;
            result := result+'"'+nomeDaColuna+'":"'+valorDaColuna+'",';
          end;
          Delete(result, Length(Result), 1);
          result := result+'},';
  
          FDQuery.Next;
        end;
        FDQuery.Refresh;
  
        Delete(result, Length(Result), 1);
        result := result+']';
  
      finally
        FDQuery.Free;
      end;
  end;
  </code></pre>