PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Datasnap com Firedac e TFDJSONDataSets #582134

05/06/2017

0

Boa noite,

Alguém já tentou utilizar FireDAC com DataSnap, através de reflection? Usando o objeto TFDJSONDataSets?
No exemplo que estou tentando fazer, o Cliente sempre levanta um erro de access violation.
Segue exemplo completo do código servidor e cliente (são extremamente simples, pequenos e objetivos), para consultar os dados de uma tabela de países:

Servidor
function TBaseServerModule.GetData: TFDJSONDataSets;
begin

  fSQLQuery.Active := False;

  result := TFDJSONDataSets.Create;

  try
    TFDJSONDataSetsWriter.ListAdd( result, fSQLQuery );
  except
    raise;
  end;

end;


Cliente - Exemplo 1 (usando proxy)
procedure TFormModeloGenericoLista.LoadData;
var
  mProxy: TServerModulePaisesClient;
  mDataSetList: TFDJSONDataSets;
begin

  mProxy := TServerModulePaisesClient.Create( ClientConnection.SQLConnection.DBXConnection );

  try

    mDataSetList := mProxy.GetData; // <- O erro é levantado aqui.

    fMemDataset.Close;
    fMemDataset.AppendData( TFDJSONDataSetsReader.GetListValueByName( mDataSetList, 'paises' ) );
    fMemDataset.Open;

  finally
    FreeAndNil( mProxy );
  end;

end;


Cliente - Exemplo 2 (com DBXCommand na mão)
procedure TFormModeloGenericoLista.LoadData;
var
  mCommand: TDBXCommand;
  mUnMarshal: TJSONUnMarshal;
  mDataSetList: TFDJSONDataSets;
begin

  mCommand := ClientConnection.SQLConnection.DBXConnection.CreateCommand;

  try

    mCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    mCommand.Text := 'TServerModulePaises.GetData' );
    mCommand.Prepare;

    ///  Executando o server method
    mCommand.ExecuteUpdate;

    ///  Validando o retorno para preenchimento do dataset
    if not mCommand.Parameters[0].Value.IsNull then
      begin

        mUnMarshal := TDBXClientCommand( mCommand.Parameters[0].ConnectionHandler ).GetJSONUnMarshaler;

        try

          // O erro dá exatamente nesta linha abaixo, quando ele tenta recuperar o TFDJSONDataSets
          mDataSetList := TFDJSONDataSets( mUnMarshal.UnMarshal( mCommand.Parameters[0].Value.GetJSONValue( False ) ) );

          fMemDataset.Close;
          fMemDataset.AppendData( TFDJSONDataSetsReader.GetListValueByName( mDataSetList, 'paises' ) );
          fMemDataset.Open;

        finally
          FreeAndNil( mUnMarshal );
        end

      end;

  finally
    FreeAndNil( mCommand );
  end;

end;
Júlio Ferreira

Júlio Ferreira

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar