Tutorial: Implementing a FireDAC RAD Server Client Application
Go Up to RAD Server Client Application
You can create a client to connect to the RAD Server Engine (EMS Server) through the FireDAC Developer API that you previously set up using a RAD Server package.
This is a client sample application based on the resource created at Tutorial: Implementing a FireDAC RAD Server Resource.
Create a VCL application and add a TDataModule to the project:
- For Delphi
- File > New > Windows VCL Application - Delphi.
- On the Projects Window, right-click Add New > Other > New Items.
- Go to Delphi > Individual files > Data Module and click OK.
- For C++:
- File > New > Windows VCL Application - C++Builder.
- On the Projects Window, right-click Add New > Other > New Items.
- Go to C++Builder > Individual Files > Data Module and click OK.
On the TDataModule place the FireDAC components you need to proceed to the JSON data from the RAD Server Engine (EMS Server).
Add the following components:
- A TFDGUIxWaitCursor component.
- A TFDSchemaAdapter component - to adapt the result of the JSON.
- Two TFDTableAdapter components - to adapt the content of the two tables.
- In the DatSTableName property set the name of the TFDQueries from the TDataModule. For this tutorial, use QEmployee and QCustomers.
- In the SchemaAdapter property set the name of the TFDSchemaAdapter.
- Two TFDMemTable components.
- Set the names to mtEmployees and mtCustomers.
- In the Adapter property set the name of the corresponding TFDTableAdapter.
- Set the CachedUpdates property to
True
. You need to enable this option to update the info from the tables.
- Two TDataSource components.
- In the DataSet property set the name of the corresponding TFDMemTable.
In the Client Form include the TDataModule in the implementation section:
- For Delphi:
implementation
{$R *.dfm}
uses Unit3;
- For C++ (In the Unit1.cpp file):
#include "Unit2.h"
Add the following components to the client form:
- Two TDBGrid components to show and update the data from the tables.
- Set the DataSource property to the data source in the TDataModule. This step is necessary to show the data on the grid.
- Two TButton components: one to get the data and the other to post the updates.
- A TEMSProvider component to set the configuration to the RAD Server Engine.
- Set the URLHost to the IP of the server, localhost by default.
- Set the URLPort to the port of the server, 8080 by default.
- A TEMSFireDACClient to connect to the TFDSchemaAdapter from the client TDataModule.
- Set the Provider property to the name of the TEMSProvider.
- Set the Resource property to the name of the resource you want to access. For this tutorial, use FireDACTest.
- Set the SchemaAdapter property to the name of the TFDSchemaAdapter from the TDataModule, for example ClientModule.FDSchemaAdapter2.
- A TActionList component to define actions to get and update the data.
- Right-click and select Action List Editor....
- Create two new actions and change the name property of the actions to ActionGetTables and ActionPostUpdates.
- Double-click the OnExecute event handler of the actions to create the procedures.
Write the code for the GetTablesExecute procedure:
- For Delphi:
procedure TClientForm.ActionGetTablesExecute(Sender: TObject);
begin
EMSFireDACClient1.GetData;
end;
- For C++ (In the Unit1.cpp file):
void __fastcall TForm1::ActionGetTablesExecute(TObject *Sender) {
EMSFireDACClient1->GetData();
}
Write the code for the PostUpdatesExecute procedure:
- For Delphi:
procedure TClientForm.ActionPostUpdatesExecute(Sender: TObject);
begin
EMSFireDACClient1.PostUpdates;
end;
- For C++ (In the Unit1.cpp file):
void __fastcall TForm1::ActionPostUpdatesExecute(TObject *Sender) {
EMSFireDACClient1->PostUpdates();
}
- Define the Action property of the Get Tables button to ActionGetTables and the OnClick event handler to ActionGetTablesExecute.
- Define the Action property of the Post Updates button to ActionPostUpdates and the OnClick event handler to ActionPostUpdatesExecute.
Testing the New RAD Server FireDAC Application
To test your project on a developer environment, make sure that the FireDAC RAD Server Resource is running on your RAD Server Engine (EMS Server).
- To run your project, press F9 or choose Run > Run.
- Click the ActionGetTables button to retrieve the data from the database.
- Update any value and click ActionPostUpdates button to save the new data in the database.