Creating the Client application (Communication Filters Tutorial)

From RAD Studio
Jump to: navigation, search

Go Up to Tutorial: Delphi DataSnap Communication Filters


Creating the Client application

1. Right-click the Group project, select Add New Project, then select VCL Forms Application and press OK.

2. Save the project in the same location as the server and set the name of the first unit to FormClientUnit.pas.

3. In the FormClientUnit design page, add a TEdit and a TButton component using the Tool Palette in the right. Change the button caption to "Reverse".

4. Add a TSQLConnection component from the Tool Palette.

TSQLConnections is the component that adds connectivity to the DataSnap Server.
Cf4.png


5. Select the Driver property of the SQLConnection and chose Datasnap.

6. Change the LoginPrompt property of the SQLConnection to False.

7. Select the Driver > Filters property of the SQLConnection and set the same filter as the server's (ZLibCompression).

The server applies a compression (ZIP type) to the data stream and the client needs to know how to decompress this data stream.

8. Change the Connected property of the SQLConnection to True.

9. Right-click the SQLConnection icon and select Generate DataSnap client classes.

  • The corresponding page is displayed. Save this unit as proxy.pas, in the same location as the previous files saved.
Cf5.png


10. Switch to the FormClientUnit, select File > Use Unit > proxy.pas, and press OK.

The proxy unit has been added to the uses clause of the client project.

11. Switch to the design page of the FormClientUnit and double-click the Reverse button you previously added.

You are redirected to the code page, where the button's functionality must be implemented.

12. In the button's corresponding procedure, implement its functionality (to change the string in the edit box to its reverse string):

  • Declare and instantiate an aClient variable:
var aClient := TServerMethods2Client.Create(SQLCOnnection1.DBXConnection);
TServerMethods2Client *aClient = TServerMethods2Client(SQLCOnnection1->DBXConnection);
  • Set the text of the TEdit component from the FormClientUnit:
Edit1.Text := aClient.ReverseString(Edit1.Text);
Edit1->Text = aClient->ReverseString(Edit1->Text);
Cf6.png


13. Add the DBXCompressionFilter unit to the uses clause of the client.

  • Otherwise, a Debugger Exception Notification will be raised with the following message: Illegal argument.
  • The DBXCompressionFilter unit has in its initialization a RegisterFilter(TTransportCompressionFilter) method that is required for the Application to register the TTransportCompressionFilter, thus making it discoverable. This way the communication can be done through compressed data.
  • To implement your own communication filter, you have to define a class that derives from TTransportFilter. The minimum implementation consists in overriding the Id, ProcessInput and ProcessOutput functions.

14. Run the client by pressing F9.

Next

Previous

See Also