Go Up to Developing DataSnap Applications
Callbacks are useful when the server needs to communicate back 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 example below:
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.
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.