Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: DataSnap with FireDAC


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Júlio César Men...

Posts: 14
Registered: 3/20/09
DataSnap with FireDAC  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 4:19 AM
Good evening,

Has anyone tried using FireDAC with DataSnap, through reflection? Using the TFDJSONDataSets object?

In the example I am trying to do, the Client always raises an access violation error.
Here is a complete example of the server and client code (they are extremely simple, small, and objective) to query data from a "country" table:

Server:

Function TBaseServerModule.GetData: TFDJSONDataSets;
Begin
  FSQLQuery.Active: = False;
  Result: = TFDJSONDataSets.Create;
  Try
    TFDJSONDataSetsWriter.ListAdd (result, fSQLQuery);
  Except
    Raise;
  End;
End;

Client (example using proxy):

Procedure TFormGenericList.LoadData;
Var
  MProxy: TServerModuleCountriesClient;
  MDataSetList: TFDJSONDataSets;
Begin
  MProxy: = TServerModuleCountriesClient.Create (
  ClientConnection.SQLConnection.DBXConnection);
  Try
    MDataSetList: = mProxy.GetData; // <- The error is raised here.
    FMemDataset.Close;
    FMemDataset.AppendData (TFDJSONDataSetsReader.GetListValueByName (mDataSetList, 'countries'));
    FMemDataset.Open;
  Finally
    FreeAndNil (mProxy);
  End;
End;

Another example of the client (with DBXCommand):

Procedure TFormGenericList.LoadData;
Var
  MCommand: TDBXCommand;
  MUnMarshal: TJSONUnMarshal;
  MDataSetList: TFDJSONDataSets;
Begin
  MCommand: = ClientConnection.SQLConnection.DBXConnection.CreateCommand;
  Try
    MCommand.CommandType: = TDBXCommandTypes.DSServerMethod;
    MCommand.Text: = 'TServerModuleCountries.GetData');
    MCommand.Prepare;
    /// Running the server method
    MCommand.ExecuteUpdate;
    /// Validating the return to fill the dataset
    If not mCommand.Parameters [0] .Value.IsNull then
      Begin
        MUnMarshal: = TDBXClientCommand (mCommand.Parameters [0] .ConnectionHandler) .GetJSONUnMarshaler;
        Try
          // The error gives exactly in this line below, when it tries to recover the TFDJSONDataSets
          MDataSetList: = TFDJSONDataSets (mUnMarshal.UnMarshal (mCommand.Parameters [0] .Value.GetJSONValue (False));
          FMemDataset.Close;
          FMemDataset.AppendData (TFDJSONDataSetsReader.GetListValueByName (mDataSetList, 'countries'));
          FMemDataset.Open;
        Finally
          FreeAndNil (mUnMarshal);
        End
      End;
  Finally
    FreeAndNil (mCommand);
  End;
End;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02