FireDAC.VSE Demo Sample
This sample shows the use of a FireDAC database connection and how to populate a database with data using an XML document.
Contents
Location
You can find the Project1 project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
- Object Pascal\Database\FireDAC\Samples\AddOn\VSE\Demo
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
- The application creates a table (test_vs) and inserts data from an XML document using a FireDAC database connection.
Note: The connection to the database does not require authentication.
How to Use the Sample
- Navigate to the location given above and open Project1.dproj.
- Press F9 or choose Run > Run.
- Click the Button1 button and the grid will be populated with data.
- Click the Button1 button again to deactivate the TFDQuery component and stop showing the data.
Files
File | Contains |
---|---|
Demo\Project1.dproj |
Contains the project itself. |
Demo\Unit1.dfm |
Contains the code of the main form. |
Demo\Unit1.pas |
Contains the main form and the main code. |
FireDAC.Comp.VSE.pas |
Contains the code for the VSE class used for parsing the XML document. |
FireDAC.Comp.VSEXML.pas |
Contains the code for the VSEXML class used for XPath. |
Implementation
- When the TForm is created, a TFDConnection executes a DROP query against the test_vs table, creates the table, and populates it with data from an XML document.
- The XML document is written at the beginning of the implementation part in the project.
<Transaction> <Request> <OrderNumber>123456</OrderNumber> <ShippingMethod>123456</ShippingMethod> </Request> <Response> <StatusCode>200</StatusCode> <StatusMesg>Order accepted</StatusMesg> <RefNumber>S0123456</RefNumber> </Response> </Transaction>
- Click the Button1 button on the main form to display (or not) the data in a TDBGrid, using a TFDQuery, a TDataSource, a TFDGUIxWaitCursor, and a TFDPhysSQLiteDriverLink.
- The TFDQuery executes a SELECT query against the test_vs table and displays the results in a TDBGrid.
- The project uses procedures which are found in the FireDAC.Comp.VSE.pas and FireDAC.Comp.VSEXML.pas units to interact with the XML document.
- In the TForm creation procedure, a TFDVSEXMLManager (the FVS code variable) is instantiated and two TFDVSESchema (the oSch code variable) are created.
- The two TFDVSESchema variables have the following TFDVSECMLFieldDefs fields: Name, DataType, Size, and XPathExpression. One TFDVSESchema is used for Request and the other one for Response. They are used for parsing the XML document.
- The FVS Manager also adds a TFDVSESessions to allow the TFDQuery to execute the query.
Uses
- FireDAC.Comp.Client.TFDConnection
- FireDAC.Comp.Client.TFDQuery
- FireDAC.Comp.UI.TFDGUIxWaitCursor
- FireDAC.Phys.SQLite.TFDPhysSQLiteDriverLink
- Data.DB.TDataSource
- Vcl.DBGrids.TDBGrid