top of page
Search
campbellsusanne78

TMS XData 4.2 Full Source: Tips and Tricks for Querying, Updating and Streaming Data



Improved: DTO validation messages now inform the full path of the property causing the error. For example, instead of "field name must be required", it shows "field country.name must be required", or "field customers[1].country.name must be required".


New: OpenAPI Importer is removed and became OpenAPI Delphi Generator, which is now open source: -dev/openapi-delphi-generator. The generated client is now not dependant on TMS BIZ anymore. Please follow the OpenAPI Delphi Generator repository for updates and upcoming features.




TMS XData 4.2 Full Source



New:XData server now returns a xdata-version header in each request.This will make it easier to tell theavailable features of the XData server being connected to. Currentversion returned is 2.


Improved:It's now possible to send blobs in JSON using format"Photo@xdata.proxy": "Customers(1)/Photo", even for blobs notflagged as lazy. In previous versions, this was only possible for lazyblobs.Sending such values will simply not modify the blob value in the server.


New:XData Music Web Application demo.A complete web application example using a TMS XData server with TMS WebCore as web front-end. Full source code is provided, and the onlineversion of the demo is available at


2 Introduction 212.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 232.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 262.4.4 References to other books . . . . . . . . . . . . . . . . . . . 262.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26


4 TDBAdvGrid: Data-aware TAdvStringGrid 1654.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 1694.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 1694.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 1694.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1704.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171


5 Assorted grid examples 1755.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 1755.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 1765.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 1785.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 1805.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 1845.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 1865.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 1885.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 1955.2.1 Creating an SQLite database with Array DML . . . . . . . . 1965.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 2025.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 2085.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 2105.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 2115.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 2115.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 2145.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 2165.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 2175.4.1 Components on the main form . . . . . . . . . . . . . . . . 2195.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 2275.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 2305.4.4 Fields and properties of the main form . . . . . . . . . . . . 2315.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 2345.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 2385.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 2395.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 2405.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 2425.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 2455.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247


6 Multi-tier, cross-platform development 2496.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 2516.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 2526.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 2546.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 2546.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 2546.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 2566.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 2566.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 2576.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 2576.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 2586.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 2586.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 2586.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 2586.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 2606.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 2606.2.1 Creating the server application . . . . . . . . . . . . . . . . 2616.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 2626.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 2666.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 2686.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 2716.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 2726.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 2756.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 2756.2.9 Implementing the service method . . . . . . . . . . . . . . . 2786.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 2806.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 2826.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 2836.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 2876.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 2926.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 2926.2.13.3 Excluding methods from Swagger . . . . . . . . . . 2946.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 2956.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 2966.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 2986.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 3036.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 3046.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 3056.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 3056.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 3066.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 3066.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 3086.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 3116.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 3156.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 3166.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 3186.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 3186.5.4 Processing the result and updating the grid . . . . . . . . . 3196.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 3236.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 3256.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 3256.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 3276.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 3286.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 3296.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 3316.6.7 Evaluating the size of Web service results . . . . . . . . . . 3326.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 3376.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 3386.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 3406.7.1 Windows application vs. Windows service . . . . . . . . . . 3416.7.2 Migrating an existing server project . . . . . . . . . . . . . . 3426.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 3426.7.2.2 Adding service information to the service container . 3436.7.2.3 Starting and stopping the server . . . . . . . . . . . 3466.7.2.4 Adding the Windows service class . . . . . . . . . . 3476.7.2.5 Helper methods to extend framework classes . . . . 3496.7.2.6 Updating the project source file . . . . . . . . . . . . 3506.7.2.7 Custom Command-line switch . . . . . . . . . . . . 3536.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 3536.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 3546.8.1.1 Settings for the database connection . . . . . . . . . 3556.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 3556.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 3556.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 3596.8.2 Defining the configuration service . . . . . . . . . . . . . . . 3596.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 3606.8.4 Implementing the configuration service . . . . . . . . . . . 3616.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 3626.8.5.1 Implementing the Singleton pattern . . . . . . . . . 3646.8.5.2 Implementing methods to start and stop the dataserver . . . . . . . . . . . . . . . . . . . . . . . . . . 3666.8.6 Adding services to the second XData server . . . . . . . . . 3686.8.6.1 Updating the postal service . . . . . . . . . . . . . . 3696.8.7 Adding start and stop to the configuration service . . . . . . 3726.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 3746.8.9 Using the configuration service . . . . . . . . . . . . . . . . 3776.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 3786.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 3786.9.2 Data module for XData connectivity . . . . . . . . . . . . . 3856.9.3 Initiating the connection from the main form . . . . . . . . 3876.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 3886.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 3946.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 3976.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 4006.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 4016.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 4036.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 4046.11.2 Implementing the config button . . . . . . . . . . . . . . . . 4066.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 4066.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 4076.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 4086.12.3 Implementing the service methods . . . . . . . . . . . . . . 4156.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 4206.13.1 Updating the service controller . . . . . . . . . . . . . . . . 4206.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 4256.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 4346.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 4356.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 4356.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 4386.14.1 Looking at the finished application . . . . . . . . . . . . . . 4406.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 4436.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 4456.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 4456.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 4466.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 4496.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page