Tutorial: Implementing a FireDAC EMS Client Application
Go Up to EMS Client Application
You can create a client to connect to the EMS Server through the FireDAC Developer API that you previously set up using an EMS package.
This is a client sample application based on the resource created at Tutorial: Implementing a FireDAC EMS Resource.
Create a VCL application and add a TDataModule to the project:
- For Delphi
- File > New > VCL Forms Application - Delphi.
- On the Project Manager, right-click Add New > Other > New Items.
- Go to Delphi Projects > Delphi Files > Data Module and click OK.
- For C++:
- File > New > VCL Forms Application - C++Builder.
- On the Project Manager, right-click Add New > Other > New Items.
- Go to C++Builder Projects > C++Builder Files > Data Module and click OK.
On the TDataModule place the FireDAC components you need to proceed to the JSON data from the 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 datasource 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 EMS Server.
- 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 EMS FireDAC Application
To test your project on a developer environment, make sure that the FireDAC EMS Resource is running on your 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.