TP2WDAConnection
TP2WDAConnection will connect to your Data Abstract server and log into your Data Abstract server’s LoginService.
Additionally, TP2WDAConnection can do other things for you — such as create a RemObjects ClientChannel or RemObjects Message.
Important note
Unless you use a LoginService with custom methods, there is probably no need to handle the following events:
OnCreateService
. BecauseTP2WDAConnection
expects a LoginService by name, not by reference.OnConnectionStringNeeded
. You don't need this unless your LoginService demands more credentials than a username and a password.
When in doubt, set the below properties and ignore the above events.
Properties
property | description |
---|---|
LoginServiceName |
Specifies the name of the service to call if authentication with the server is needed, typically this is LoginService . |
MessageType |
RemObjects sends (and receives) messages that get serialized (and deserialized). This property specifies the structure of the messages. Possible values are mtAuto or mtBin or mtJSON . When set to mtAuto , TP2WDAConnection will try and auto-detect the message type from the URL to the server. |
Password |
Your password for the login service. |
URL |
Specifies the URL to the server, for example: http://localhost:7099/bin |
Username |
Your username for the login service. |
Methods
method | description |
---|---|
CreateChannel |
Channels facilitate communication between client and server, or between different services. There is probably no need to create a channel manually, but if you ever need to do it, this method returns a new channel for you over the HTTP protocol. |
CreateMessage |
Messages are sent over channels between client and server, or between different services. There is probably no need to create a message manually, but if you ever need to do it, this method creates a new (binary or JSON) message for you. See also: TP2WDAConnection.MessageType . |
Events
event | description |
---|---|
OnCreateService |
Most of the time, you will specify a LoginService by name and be done with it. In most cases there is no need to add any custom methods to the LoginService. However, if your LoginService does have custom methods you would need to call from Delphi, this event is where to create it. See also: OnCreateService. |
OnConnectionStringNeeded |
If your LoginService needs a username/password combination only, there is no need to respond to OnConnectionStringNeeded . However, if your LoginService needs a custom login string to authenticate, this is where to provide it. See also: OnConnectionStringNeeded. |
OnCreateService
Here is an example of a LoginService 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 TP2WDAConnection.OnCreateService
:
type
TMyLoginService = class external name 'MyProject.LoginService'(TBaseLoginService)
procedure MyCustomMethod(onSuccess: TOnSuccess; onFailure: TOnFailure);
end;
procedure TForm1.ConnectionCreateService(Sender: TObject; const Channel: TROClientChannel; const Msg: TROMessage; var Service: TROService);
begin
Service := TMyLoginService.new(Channel, Msg, Connection.LoginServiceName);
end;
Should you need access to your custom LoginService (to call a custom method on it, for example), this is how to get it:
var
MyLoginService: TMyLoginService;
begin
MyLoginService := Connection.LoginService as TMyLoginService;
...
end;
OnConnectionStringNeeded
Your LoginService probably needs a username/password combination only. However, if your LoginService needs a custom login string to authenticate, here is an example how to provide it: