Go Up to DataSnap Server Application
Callbacks are useful when the server needs to communicate with the client while executing a server method. Callbacks allow a JSON parameter to be passed back to the client and the client can return a JSON value back to the server.
In order to pass a callback, the server method needs to have a parameter of type TDBXCallback, like in the following example:
procedure Callback(const PCallback: TDBXCallback);
In the server implementation, the callback can be invoked at any time:
The invocation is synchronous and it returns a client JSON value.
On the client side, you need to extend a TDBXCallback class and override the Execute method:
TCallbackClient = class(TDBXCallback) function Execute(const Arg: TJSONValue): TJSONValue; override; end;
The server method needs to be invoked with an instance of the client callback class.
The callback parameters are owned by the proxy instance or server and released upon completion.