TP2WDARemoteAdapter
TP2WDARemoteAdapter will use your TP2WDAConnection and connect to your Data Abstract server’s DataService. If your Data Abstract server has more than one DataService, you probably need more than one TP2WDARemoteAdapters.
This component is a wrapper for RemoteDataAdapter and does most of the heavy lifting, including retrieving and updating data.
TP2WDARemoteAdapter encapsulates all the information needed to communicate with the server and to encode and decode data via a data streamer.
Properties
property | description |
---|---|
Connected |
Determines whether a connection has been established to the Data Abstract server and is active. Set Connected to True to open the connection. Set Connected to False to terminate the connection. |
Connection |
You must link this property up to a TP2WDAConnection component for your TP2WDARemoteAdapter to find (and potentially log into) the Data Abstract server. |
DataServiceName |
Specifies the name of the service to retrieve data from, typically this is DataService . |
DataStreamer |
A data streamer is responsible for encoding and decoding data packets that are transmitted between client and server over the network. The format in which these streams are encoded is determined by this property. Possible values are dsBin or dsJSON . |
Options |
Please see: TAdapterOptions |
Events
event | description |
---|---|
OnError |
Fires when an error occurs while logging in, retrieving data, or updating data. If you don't handle this event, it is possible for TP2WDARemoteAdapter to raise an exception. See also: TAdapterOptions.RetryLoginOnError . |
OnLoginNeededEx |
Allows for your GUI to display a login dialog when a username and password is needed. OnLoginNeeded and OnLoginNeededEx are mutually exclusive. You only need to handle one of them. OnLoginNeededEx MUST return a promise and resolve to a Boolean value. Do NOT reject the promise. |
OnLoginSuccess |
Fires when this TP2WDARemoteAdapter has successfully logged into the server. |
OnLogoutSuccess |
Fires when this TP2WDARemoteAdapter has successfully logged out of the server. |
Unless you use a DataService with custom methods, there is probably no need to handle the following events:
event | description |
---|---|
OnCreateService |
Most of the time, you will specify a DataService by name and be done with it. However, if your DataService has custom methods you would need to call from Delphi, this event is where to create it. See also: OnCreateService. |
OnLoginNeeded |
You should probably ignore this event and handle the OnLoginNeededEx event instead. |
OnGetConnected |
This is handled internally by the component. |
When in doubt, handle OnLoginNeededEx
and ignore the above events.
TAdapterOptions
option | description |
---|---|
AutoOpenDataSet |
When True , the TP2WDATable or TP2WDAQuery components using this TP2WDARemoteAdapter will automatically get opened. |
RetryLoginOnError |
When True , this TP2WDARemoteAdapter will automatically try and login again when an error occurred. |
OnCreateService
Here is an example of a DataService with one or more custom methods. You would need to define a so-called "external class" and then create and return an instance of this class as a response to TP2WDARemoteAdapter.OnCreateService
:
type
TMyDataService = class external name 'MyProject.DataService'(TDataAbstractService)
procedure MyCustomMethod(onSuccess: TOnSuccess; onFailure: TOnFailure);
end;
procedure TForm1.DataAdapterCreateService(Sender: TObject; const Channel: TROClientChannel; const Msg: TROMessage; var Service: TROService);
begin
Service := TMyDataService.new(Channel, Msg, DataAdapter.DataServiceName);
end;
Should you need access to your custom DataService (to call a custom method on it, for example), this is how to get it: