Books Writers Publishers Languages

Hands-on with Delphi - Volume 3

Published by : FlixEngineering

Writed by : Dr Holger Flick

Published date : 22/07/2021

ISBN-13 : 9798690375928

Language : English English

Web site : https://www.holgerscode.com/books/2021/07/23/multi-tier-cross-platform-data-access-and-visualization-in-grids/

About Hands-on with Delphi - Volume 3

Learn to build and deploy modern, multi-tier data-driven Delphi applications for multiple platforms with the Visual Component Library (VCL), FireMonkey (FMX), and TMS WEB Core!

Become a VCL UI Grid Control Insider!

Get to know TAdvStringGrid and its data-aware counterpart TDBAdvGrid in detail. Starting with basic examples, use HTML, insert images, export and import data, customize navigation and mouse-interaction. In-depth look at sorting, editing, filters, and grouping with real-world examples

Efficiently work with data from text files, embed it in your executable, or use FireDAC with SQLite. Write asynchronous, non-blocking code

Use vector images in your grid, browse ZIP archives, and export reports to Microsoft Excel and Adobe PDF

Take the fear out of complex multi-tier Delphi projects!

Step-by-step you will learn to build a database, add a Web service, write clients for Windows, Smartphones, and the Web!

Learn how to deploy your Web services as Windows Services and manage them using a Web interface as part of your service

Test and add documentation with Swagger UI

Easily retrieve diagnostic information to monitor your services with Windows Management Instrumentation

Build Web and cross-platform desktop applications with TMS Web Core and the powerful TMS Miletus sharing the same code base

Where to buy ?

This book has the ISBN13 "9798690375928".
If it is still available for sale, you can order it in your favorite bookstore, by its publisher or online at
Amazon CA, Amazon FR, Amazon JP, Amazon UK or Amazon USA depending on your country.

Table of content

1 Preface 1.1 About the series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.2 Required programming skills . . . . . . . . . . . . . . . . . . . . . . 18 1.3 Structure of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.4 Technical review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.5 Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2 Introduction 21 2.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 23 2.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 26 2.4.4 References to other books . . . . . . . . . . . . . . . . . . . 26 2.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26

I VCL Grid Controls

3 TAdvStringGrid 29 3.1 Compatibility with Delphi versions . . . . . . . . . . . . . . . . . . . 29 3.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.2.1 Cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.2.2 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.2.3 Writing text into cells . . . . . . . . . . . . . . . . . . . . . 34 3.2.4 Handling mouse clicks . . . . . . . . . . . . . . . . . . . . . 36 3.2.4.1 OnCellClick with row selection . . . . . . . . . . . . 36 3.2.4.2 Determine selected cell(s) without mouse click . . . 37 3.2.4.3 Determine selected rows(s) without mouse click . . 38 3.2.5 Changing dimensions . . . . . . . . . . . . . . . . . . . . . 38 3.2.6 Quickly generating test data . . . . . . . . . . . . . . . . . . 38 3.2.7 Bundled examples . . . . . . . . . . . . . . . . . . . . . . . 41 3.2.7.1 List of examples . . . . . . . . . . . . . . . . . . . . 42 3.2.7.2 Locating the examples . . . . . . . . . . . . . . . . . 44 3.2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 3.3 Static, virtual, and dynamic cells . . . . . . . . . . . . . . . . . . . . 45 3.3.1 Static cell properties . . . . . . . . . . . . . . . . . . . . . . 46 3.3.2 Using virtual cells . . . . . . . . . . . . . . . . . . . . . . . 48 3.3.2.1 Changing cell data for display . . . . . . . . . . . . . 50 3.3.2.2 Provide data on demand using virtual cells . . . . . 53 3.3.3 Dynamic cell properties . . . . . . . . . . . . . . . . . . . . 54 3.3.3.1 State of the grid . . . . . . . . . . . . . . . . . . . . 54 3.3.3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.3.3.3 Color gradient . . . . . . . . . . . . . . . . . . . . . 57 3.3.3.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . 59 3.3.3.5 Mouse cursor . . . . . . . . . . . . . . . . . . . . . . 61 3.4 Using HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.4.1 Images stored in PictureContainer and GridImages . . . . . 63 3.4.2 Supported tags . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.4.3 Where to insert HTML tags . . . . . . . . . . . . . . . . . . 76 3.5 Organizing rows and columns . . . . . . . . . . . . . . . . . . . . . . 76 3.5.1 Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 3.5.1.1 Persisting column widths . . . . . . . . . . . . . . . 79 3.5.1.2 Stretching . . . . . . . . . . . . . . . . . . . . . . . 79 3.5.2 Reordering (moving) . . . . . . . . . . . . . . . . . . . . . . 81 3.5.3 Hidden columns and rows . . . . . . . . . . . . . . . . . . . 85 3.5.4 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 3.5.5 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 3.6 Loading and writing grid data . . . . . . . . . . . . . . . . . . . . . . 98 3.6.1 Customizing saving and loading . . . . . . . . . . . . . . . . 100 3.6.2 Creating PDF files . . . . . . . . . . . . . . . . . . . . . . . 101 3.6.2.1 Document options . . . . . . . . . . . . . . . . . . . 101 3.6.2.2 Document information . . . . . . . . . . . . . . . . 106 3.6.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . 106 3.7 Navigating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 3.7.1 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 3.7.2 Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 3.8 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 3.8.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 3.8.2 Storing and loading . . . . . . . . . . . . . . . . . . . . . . 130 3.8.3 Sort styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 3.8.3.1 Manually specifying the cell format . . . . . . . . . 133 3.8.3.2 Custom sorting . . . . . . . . . . . . . . . . . . . . . 134 3.8.4 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 3.8.5 Ignoring columns . . . . . . . . . . . . . . . . . . . . . . . . 138 3.8.6 Row indexes before and after sorting . . . . . . . . . . . . . 139 3.8.7 Triggering sorting at run-time . . . . . . . . . . . . . . . . . 139 3.8.7.1 Single column . . . . . . . . . . . . . . . . . . . . . 140 3.8.7.2 Sort column sequences . . . . . . . . . . . . . . . . 140 3.8.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 3.9 Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 3.9.1 Enabling editing for all cells . . . . . . . . . . . . . . . . . . 145 3.9.2 Read-only cells . . . . . . . . . . . . . . . . . . . . . . . . . 147 3.9.3 Starting the edit process using code . . . . . . . . . . . . . . 148 3.9.4 Inplace editors . . . . . . . . . . . . . . . . . . . . . . . . . 148 3.9.4.1 Defining an inplace editor . . . . . . . . . . . . . . . 150 3.9.4.2 Restricting the length of input . . . . . . . . . . . . 151 3.9.4.3 Using masks . . . . . . . . . . . . . . . . . . . . . . 151 3.9.4.4 Spin editors . . . . . . . . . . . . . . . . . . . . . . . 154 3.9.4.5 Combo boxes . . . . . . . . . . . . . . . . . . . . . . 156 3.9.5 Validating user input . . . . . . . . . . . . . . . . . . . . . . 160 3.10 Undo & Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

4 TDBAdvGrid: Data-aware TAdvStringGrid 165 4.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 169 4.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 169 4.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 169 4.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171

II Hands-on Examples

5 Assorted grid examples 175 5.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 175 5.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 176 5.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 178 5.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 180 5.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 184 5.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 186 5.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 188 5.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 195 5.2.1 Creating an SQLite database with Array DML . . . . . . . . 196 5.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 202 5.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 208 5.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 210 5.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 211 5.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 211 5.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 214 5.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 216 5.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 217 5.4.1 Components on the main form . . . . . . . . . . . . . . . . 219 5.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 227 5.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 230 5.4.4 Fields and properties of the main form . . . . . . . . . . . . 231 5.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 234 5.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 238 5.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 239 5.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 240 5.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 242 5.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 245 5.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247

6 Multi-tier, cross-platform development 249 6.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 251 6.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 252 6.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 254 6.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 254 6.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 254 6.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 256 6.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 256 6.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 257 6.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 257 6.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 258 6.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 258 6.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 258 6.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 258 6.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 260 6.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 260 6.2.1 Creating the server application . . . . . . . . . . . . . . . . 261 6.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 262 6.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 266 6.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 268 6.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 271 6.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 272 6.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 275 6.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 275 6.2.9 Implementing the service method . . . . . . . . . . . . . . . 278 6.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 280 6.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 282 6.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 283 6.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 287 6.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 292 6.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 292 6.2.13.3 Excluding methods from Swagger . . . . . . . . . . 294 6.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 295 6.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 296 6.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 298 6.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 303 6.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 304 6.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 305 6.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 305 6.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 306 6.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 306 6.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 308 6.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 311 6.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 315 6.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 316 6.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 318 6.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 318 6.5.4 Processing the result and updating the grid . . . . . . . . . 319 6.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 323 6.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 325 6.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 325 6.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 327 6.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 328 6.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 329 6.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 331 6.6.7 Evaluating the size of Web service results . . . . . . . . . . 332 6.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 337 6.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 338 6.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 340 6.7.1 Windows application vs. Windows service . . . . . . . . . . 341 6.7.2 Migrating an existing server project . . . . . . . . . . . . . . 342 6.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 342 6.7.2.2 Adding service information to the service container . 343 6.7.2.3 Starting and stopping the server . . . . . . . . . . . 346 6.7.2.4 Adding the Windows service class . . . . . . . . . . 347 6.7.2.5 Helper methods to extend framework classes . . . . 349 6.7.2.6 Updating the project source file . . . . . . . . . . . . 350 6.7.2.7 Custom Command-line switch . . . . . . . . . . . . 353 6.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 353 6.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 354 6.8.1.1 Settings for the database connection . . . . . . . . . 355 6.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 355 6.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 355 6.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 359 6.8.2 Defining the configuration service . . . . . . . . . . . . . . . 359 6.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 360 6.8.4 Implementing the configuration service . . . . . . . . . . . 361 6.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 362 6.8.5.1 Implementing the Singleton pattern . . . . . . . . . 364 6.8.5.2 Implementing methods to start and stop the data server . . . . . . . . . . . . . . . . . . . . . . . . . . 366 6.8.6 Adding services to the second XData server . . . . . . . . . 368 6.8.6.1 Updating the postal service . . . . . . . . . . . . . . 369 6.8.7 Adding start and stop to the configuration service . . . . . . 372 6.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 374 6.8.9 Using the configuration service . . . . . . . . . . . . . . . . 377 6.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 378 6.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 378 6.9.2 Data module for XData connectivity . . . . . . . . . . . . . 385 6.9.3 Initiating the connection from the main form . . . . . . . . 387 6.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 388 6.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 394 6.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 397 6.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 400 6.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 401 6.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 403 6.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 404 6.11.2 Implementing the config button . . . . . . . . . . . . . . . . 406 6.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 406 6.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 407 6.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 408 6.12.3 Implementing the service methods . . . . . . . . . . . . . . 415 6.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 420 6.13.1 Updating the service controller . . . . . . . . . . . . . . . . 420 6.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 425 6.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 434 6.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 435 6.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 435 6.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 438 6.14.1 Looking at the finished application . . . . . . . . . . . . . . 440 6.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 443 6.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 445 6.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 445 6.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 446 6.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 449 6.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451

7 Appendix 7.1 Internet Component Suite (ICS) . . . . . . . . . . . . . . . . . . . . . 453 7.1.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 7.1.2 List of components . . . . . . . . . . . . . . . . . . . . . . . 454 7.1.3 List of examples . . . . . . . . . . . . . . . . . . . . . . . . 455 7.1.4 Legal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 7.2 TColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 7.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

1 Preface 1.1 About the series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 Required programming skills . . . . . . . . . . . . . . . . . . . . . . 18
1.3 Structure of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Technical review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5 Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2 Introduction
2.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 26
2.4.4 References to other books . . . . . . . . . . . . . . . . . . . 26
2.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26

I VCL Grid Controls

3 TAdvStringGrid
3.1 Compatibility with Delphi versions . . . . . . . . . . . . . . . . . . . 29
3.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.1 Cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.2 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.3 Writing text into cells . . . . . . . . . . . . . . . . . . . . . 34
3.2.4 Handling mouse clicks . . . . . . . . . . . . . . . . . . . . . 36
3.2.4.1 OnCellClick with row selection . . . . . . . . . . . . 36
3.2.4.2 Determine selected cell(s) without mouse click . . . 37
3.2.4.3 Determine selected rows(s) without mouse click . . 38
3.2.5 Changing dimensions . . . . . . . . . . . . . . . . . . . . . 38
3.2.6 Quickly generating test data . . . . . . . . . . . . . . . . . . 38
3.2.7 Bundled examples . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.7.1 List of examples . . . . . . . . . . . . . . . . . . . . 42
3.2.7.2 Locating the examples . . . . . . . . . . . . . . . . . 44
3.2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Static, virtual, and dynamic cells . . . . . . . . . . . . . . . . . . . . 45
3.3.1 Static cell properties . . . . . . . . . . . . . . . . . . . . . . 46
3.3.2 Using virtual cells . . . . . . . . . . . . . . . . . . . . . . . 48
3.3.2.1 Changing cell data for display . . . . . . . . . . . . . 50
3.3.2.2 Provide data on demand using virtual cells . . . . . 53
3.3.3 Dynamic cell properties . . . . . . . . . . . . . . . . . . . . 54
3.3.3.1 State of the grid . . . . . . . . . . . . . . . . . . . . 54
3.3.3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.3.3.3 Color gradient . . . . . . . . . . . . . . . . . . . . . 57
3.3.3.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . 59
3.3.3.5 Mouse cursor . . . . . . . . . . . . . . . . . . . . . . 61
3.4 Using HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.4.1 Images stored in PictureContainer and GridImages . . . . . 63
3.4.2 Supported tags . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.4.3 Where to insert HTML tags . . . . . . . . . . . . . . . . . . 76
3.5 Organizing rows and columns . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1 Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1.1 Persisting column widths . . . . . . . . . . . . . . . 79
3.5.1.2 Stretching . . . . . . . . . . . . . . . . . . . . . . . 79
3.5.2 Reordering (moving) . . . . . . . . . . . . . . . . . . . . . . 81
3.5.3 Hidden columns and rows . . . . . . . . . . . . . . . . . . . 85
3.5.4 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.5 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.6 Loading and writing grid data . . . . . . . . . . . . . . . . . . . . . . 98
3.6.1 Customizing saving and loading . . . . . . . . . . . . . . . . 100
3.6.2 Creating PDF files . . . . . . . . . . . . . . . . . . . . . . . 101
3.6.2.1 Document options . . . . . . . . . . . . . . . . . . . 101
3.6.2.2 Document information . . . . . . . . . . . . . . . . 106
3.6.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . 106
3.7 Navigating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.7.1 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.7.2 Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.8 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
3.8.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.8.2 Storing and loading . . . . . . . . . . . . . . . . . . . . . . 130
3.8.3 Sort styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.8.3.1 Manually specifying the cell format . . . . . . . . . 133
3.8.3.2 Custom sorting . . . . . . . . . . . . . . . . . . . . . 134
3.8.4 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.8.5 Ignoring columns . . . . . . . . . . . . . . . . . . . . . . . . 138
3.8.6 Row indexes before and after sorting . . . . . . . . . . . . . 139
3.8.7 Triggering sorting at run-time . . . . . . . . . . . . . . . . . 139
3.8.7.1 Single column . . . . . . . . . . . . . . . . . . . . . 140
3.8.7.2 Sort column sequences . . . . . . . . . . . . . . . . 140
3.8.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
3.9 Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
3.9.1 Enabling editing for all cells . . . . . . . . . . . . . . . . . . 145
3.9.2 Read-only cells . . . . . . . . . . . . . . . . . . . . . . . . . 147
3.9.3 Starting the edit process using code . . . . . . . . . . . . . . 148
3.9.4 Inplace editors . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.9.4.1 Defining an inplace editor . . . . . . . . . . . . . . . 150
3.9.4.2 Restricting the length of input . . . . . . . . . . . . 151
3.9.4.3 Using masks . . . . . . . . . . . . . . . . . . . . . . 151
3.9.4.4 Spin editors . . . . . . . . . . . . . . . . . . . . . . . 154
3.9.4.5 Combo boxes . . . . . . . . . . . . . . . . . . . . . . 156
3.9.5 Validating user input . . . . . . . . . . . . . . . . . . . . . . 160
3.10 Undo & Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

4 TDBAdvGrid: Data-aware TAdvStringGrid
4.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 169
4.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 169
4.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 169
4.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171

II Hands-on Examples

5 Assorted grid examples
5.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 175
5.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 176
5.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 178
5.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 180
5.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 184
5.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 186
5.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 188
5.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 195
5.2.1 Creating an SQLite database with Array DML . . . . . . . . 196
5.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 202
5.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 208
5.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 210
5.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 211
5.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 211
5.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 214
5.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 216
5.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 217
5.4.1 Components on the main form . . . . . . . . . . . . . . . . 219
5.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 227
5.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 230
5.4.4 Fields and properties of the main form . . . . . . . . . . . . 231
5.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 234
5.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 238
5.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 239
5.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 240
5.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 242
5.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 245
5.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247

6 Multi-tier, cross-platform development
6.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 251
6.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 252
6.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 254
6.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 256
6.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 256
6.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 258
6.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 258
6.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 260
6.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 260
6.2.1 Creating the server application . . . . . . . . . . . . . . . . 261
6.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 262
6.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 266
6.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 268
6.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 271
6.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 272
6.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 275
6.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 275
6.2.9 Implementing the service method . . . . . . . . . . . . . . . 278
6.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 280
6.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 282
6.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 283
6.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 287
6.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 292
6.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 292
6.2.13.3 Excluding methods from Swagger . . . . . . . . . . 294
6.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 295
6.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 296
6.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 298
6.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 303
6.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 304
6.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 305
6.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 305
6.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 306
6.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 306
6.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 308
6.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 311
6.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 315
6.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 316
6.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 318
6.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 318
6.5.4 Processing the result and updating the grid . . . . . . . . . 319
6.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 323
6.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 325
6.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 325
6.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 327
6.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 328
6.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 329
6.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 331
6.6.7 Evaluating the size of Web service results . . . . . . . . . . 332
6.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 337
6.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 338
6.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 340
6.7.1 Windows application vs. Windows service . . . . . . . . . . 341
6.7.2 Migrating an existing server project . . . . . . . . . . . . . . 342
6.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 342
6.7.2.2 Adding service information to the service container . 343
6.7.2.3 Starting and stopping the server . . . . . . . . . . . 346
6.7.2.4 Adding the Windows service class . . . . . . . . . . 347
6.7.2.5 Helper methods to extend framework classes . . . . 349
6.7.2.6 Updating the project source file . . . . . . . . . . . . 350
6.7.2.7 Custom Command-line switch . . . . . . . . . . . . 353
6.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 353
6.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 354
6.8.1.1 Settings for the database connection . . . . . . . . . 355
6.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 355
6.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 355
6.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 359
6.8.2 Defining the configuration service . . . . . . . . . . . . . . . 359
6.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 360
6.8.4 Implementing the configuration service . . . . . . . . . . . 361
6.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 362
6.8.5.1 Implementing the Singleton pattern . . . . . . . . . 364
6.8.5.2 Implementing methods to start and stop the data server . . . . . . . . . . . . . . . . . . . . . . . . . . 366
6.8.6 Adding services to the second XData server . . . . . . . . . 368
6.8.6.1 Updating the postal service . . . . . . . . . . . . . . 369
6.8.7 Adding start and stop to the configuration service . . . . . . 372
6.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 374
6.8.9 Using the configuration service . . . . . . . . . . . . . . . . 377
6.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 378
6.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 378
6.9.2 Data module for XData connectivity . . . . . . . . . . . . . 385
6.9.3 Initiating the connection from the main form . . . . . . . . 387
6.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 388
6.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 394
6.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 397
6.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 400
6.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 401
6.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 403
6.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 404
6.11.2 Implementing the config button . . . . . . . . . . . . . . . . 406
6.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 406
6.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 407
6.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 408
6.12.3 Implementing the service methods . . . . . . . . . . . . . . 415
6.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 420
6.13.1 Updating the service controller . . . . . . . . . . . . . . . . 420
6.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 425
6.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 434
6.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 435
6.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 435
6.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 438
6.14.1 Looking at the finished application . . . . . . . . . . . . . . 440
6.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 443
6.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 445
6.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 445
6.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 446
6.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 449
6.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451

7 Appendix
7.1 Internet Component Suite (ICS) . . . . . . . . . . . . . . . . . . . . . 453
7.1.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
7.1.2 List of components . . . . . . . . . . . . . . . . . . . . . . . 454
7.1.3 List of examples . . . . . . . . . . . . . . . . . . . . . . . . 455
7.1.4 Legal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
7.2 TColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
7.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

1 Preface 1.1 About the series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 Required programming skills . . . . . . . . . . . . . . . . . . . . . . 18
1.3 Structure of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Technical review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5 Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2 Introduction
2.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 26
2.4.4 References to other books . . . . . . . . . . . . . . . . . . . 26
2.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26

I VCL Grid Controls

3 TAdvStringGrid
3.1 Compatibility with Delphi versions . . . . . . . . . . . . . . . . . . . 29
3.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.1 Cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.2 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.3 Writing text into cells . . . . . . . . . . . . . . . . . . . . . 34
3.2.4 Handling mouse clicks . . . . . . . . . . . . . . . . . . . . . 36
3.2.4.1 OnCellClick with row selection . . . . . . . . . . . . 36
3.2.4.2 Determine selected cell(s) without mouse click . . . 37
3.2.4.3 Determine selected rows(s) without mouse click . . 38
3.2.5 Changing dimensions . . . . . . . . . . . . . . . . . . . . . 38
3.2.6 Quickly generating test data . . . . . . . . . . . . . . . . . . 38
3.2.7 Bundled examples . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.7.1 List of examples . . . . . . . . . . . . . . . . . . . . 42
3.2.7.2 Locating the examples . . . . . . . . . . . . . . . . . 44
3.2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Static, virtual, and dynamic cells . . . . . . . . . . . . . . . . . . . . 45
3.3.1 Static cell properties . . . . . . . . . . . . . . . . . . . . . . 46
3.3.2 Using virtual cells . . . . . . . . . . . . . . . . . . . . . . . 48
3.3.2.1 Changing cell data for display . . . . . . . . . . . . . 50
3.3.2.2 Provide data on demand using virtual cells . . . . . 53
3.3.3 Dynamic cell properties . . . . . . . . . . . . . . . . . . . . 54
3.3.3.1 State of the grid . . . . . . . . . . . . . . . . . . . . 54
3.3.3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.3.3.3 Color gradient . . . . . . . . . . . . . . . . . . . . . 57
3.3.3.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . 59
3.3.3.5 Mouse cursor . . . . . . . . . . . . . . . . . . . . . . 61
3.4 Using HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.4.1 Images stored in PictureContainer and GridImages . . . . . 63
3.4.2 Supported tags . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.4.3 Where to insert HTML tags . . . . . . . . . . . . . . . . . . 76
3.5 Organizing rows and columns . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1 Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1.1 Persisting column widths . . . . . . . . . . . . . . . 79
3.5.1.2 Stretching . . . . . . . . . . . . . . . . . . . . . . . 79
3.5.2 Reordering (moving) . . . . . . . . . . . . . . . . . . . . . . 81
3.5.3 Hidden columns and rows . . . . . . . . . . . . . . . . . . . 85
3.5.4 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.5 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.6 Loading and writing grid data . . . . . . . . . . . . . . . . . . . . . . 98
3.6.1 Customizing saving and loading . . . . . . . . . . . . . . . . 100
3.6.2 Creating PDF files . . . . . . . . . . . . . . . . . . . . . . . 101
3.6.2.1 Document options . . . . . . . . . . . . . . . . . . . 101
3.6.2.2 Document information . . . . . . . . . . . . . . . . 106
3.6.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . 106
3.7 Navigating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.7.1 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.7.2 Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.8 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
3.8.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.8.2 Storing and loading . . . . . . . . . . . . . . . . . . . . . . 130
3.8.3 Sort styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.8.3.1 Manually specifying the cell format . . . . . . . . . 133
3.8.3.2 Custom sorting . . . . . . . . . . . . . . . . . . . . . 134
3.8.4 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.8.5 Ignoring columns . . . . . . . . . . . . . . . . . . . . . . . . 138
3.8.6 Row indexes before and after sorting . . . . . . . . . . . . . 139
3.8.7 Triggering sorting at run-time . . . . . . . . . . . . . . . . . 139
3.8.7.1 Single column . . . . . . . . . . . . . . . . . . . . . 140
3.8.7.2 Sort column sequences . . . . . . . . . . . . . . . . 140
3.8.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
3.9 Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
3.9.1 Enabling editing for all cells . . . . . . . . . . . . . . . . . . 145
3.9.2 Read-only cells . . . . . . . . . . . . . . . . . . . . . . . . . 147
3.9.3 Starting the edit process using code . . . . . . . . . . . . . . 148
3.9.4 Inplace editors . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.9.4.1 Defining an inplace editor . . . . . . . . . . . . . . . 150
3.9.4.2 Restricting the length of input . . . . . . . . . . . . 151
3.9.4.3 Using masks . . . . . . . . . . . . . . . . . . . . . . 151
3.9.4.4 Spin editors . . . . . . . . . . . . . . . . . . . . . . . 154
3.9.4.5 Combo boxes . . . . . . . . . . . . . . . . . . . . . . 156
3.9.5 Validating user input . . . . . . . . . . . . . . . . . . . . . . 160
3.10 Undo & Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

4 TDBAdvGrid: Data-aware TAdvStringGrid
4.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 169
4.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 169
4.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 169
4.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171

II Hands-on Examples

5 Assorted grid examples
5.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 175
5.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 176
5.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 178
5.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 180
5.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 184
5.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 186
5.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 188
5.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 195
5.2.1 Creating an SQLite database with Array DML . . . . . . . . 196
5.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 202
5.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 208
5.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 210
5.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 211
5.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 211
5.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 214
5.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 216
5.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 217
5.4.1 Components on the main form . . . . . . . . . . . . . . . . 219
5.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 227
5.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 230
5.4.4 Fields and properties of the main form . . . . . . . . . . . . 231
5.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 234
5.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 238
5.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 239
5.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 240
5.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 242
5.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 245
5.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247

6 Multi-tier, cross-platform development
6.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 251
6.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 252
6.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 254
6.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 256
6.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 256
6.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 258
6.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 258
6.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 260
6.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 260
6.2.1 Creating the server application . . . . . . . . . . . . . . . . 261
6.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 262
6.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 266
6.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 268
6.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 271
6.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 272
6.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 275
6.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 275
6.2.9 Implementing the service method . . . . . . . . . . . . . . . 278
6.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 280
6.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 282
6.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 283
6.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 287
6.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 292
6.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 292
6.2.13.3 Excluding methods from Swagger . . . . . . . . . . 294
6.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 295
6.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 296
6.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 298
6.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 303
6.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 304
6.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 305
6.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 305
6.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 306
6.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 306
6.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 308
6.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 311
6.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 315
6.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 316
6.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 318
6.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 318
6.5.4 Processing the result and updating the grid . . . . . . . . . 319
6.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 323
6.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 325
6.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 325
6.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 327
6.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 328
6.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 329
6.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 331
6.6.7 Evaluating the size of Web service results . . . . . . . . . . 332
6.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 337
6.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 338
6.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 340
6.7.1 Windows application vs. Windows service . . . . . . . . . . 341
6.7.2 Migrating an existing server project . . . . . . . . . . . . . . 342
6.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 342
6.7.2.2 Adding service information to the service container . 343
6.7.2.3 Starting and stopping the server . . . . . . . . . . . 346
6.7.2.4 Adding the Windows service class . . . . . . . . . . 347
6.7.2.5 Helper methods to extend framework classes . . . . 349
6.7.2.6 Updating the project source file . . . . . . . . . . . . 350
6.7.2.7 Custom Command-line switch . . . . . . . . . . . . 353
6.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 353
6.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 354
6.8.1.1 Settings for the database connection . . . . . . . . . 355
6.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 355
6.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 355
6.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 359
6.8.2 Defining the configuration service . . . . . . . . . . . . . . . 359
6.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 360
6.8.4 Implementing the configuration service . . . . . . . . . . . 361
6.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 362
6.8.5.1 Implementing the Singleton pattern . . . . . . . . . 364
6.8.5.2 Implementing methods to start and stop the data server . . . . . . . . . . . . . . . . . . . . . . . . . . 366
6.8.6 Adding services to the second XData server . . . . . . . . . 368
6.8.6.1 Updating the postal service . . . . . . . . . . . . . . 369
6.8.7 Adding start and stop to the configuration service . . . . . . 372
6.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 374
6.8.9 Using the configuration service . . . . . . . . . . . . . . . . 377
6.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 378
6.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 378
6.9.2 Data module for XData connectivity . . . . . . . . . . . . . 385
6.9.3 Initiating the connection from the main form . . . . . . . . 387
6.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 388
6.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 394
6.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 397
6.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 400
6.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 401
6.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 403
6.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 404
6.11.2 Implementing the config button . . . . . . . . . . . . . . . . 406
6.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 406
6.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 407
6.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 408
6.12.3 Implementing the service methods . . . . . . . . . . . . . . 415
6.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 420
6.13.1 Updating the service controller . . . . . . . . . . . . . . . . 420
6.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 425
6.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 434
6.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 435
6.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 435
6.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 438
6.14.1 Looking at the finished application . . . . . . . . . . . . . . 440
6.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 443
6.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 445
6.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 445
6.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 446
6.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 449
6.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451

7 Appendix
7.1 Internet Component Suite (ICS) . . . . . . . . . . . . . . . . . . . . . 453
7.1.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
7.1.2 List of components . . . . . . . . . . . . . . . . . . . . . . . 454
7.1.3 List of examples . . . . . . . . . . . . . . . . . . . . . . . . 455
7.1.4 Legal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
7.2 TColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
7.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

1 Preface
1.1 About the series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 Required programming skills . . . . . . . . . . . . . . . . . . . . . . 18
1.3 Structure of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Technical review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5 Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2 Introduction
2.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 26
2.4.4 References to other books . . . . . . . . . . . . . . . . . . . 26
2.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26

I VCL Grid Controls

3 TAdvStringGrid
3.1 Compatibility with Delphi versions . . . . . . . . . . . . . . . . . . . 29
3.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.1 Cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.2 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.3 Writing text into cells . . . . . . . . . . . . . . . . . . . . . 34
3.2.4 Handling mouse clicks . . . . . . . . . . . . . . . . . . . . . 36
3.2.4.1 OnCellClick with row selection . . . . . . . . . . . . 36
3.2.4.2 Determine selected cell(s) without mouse click . . . 37
3.2.4.3 Determine selected rows(s) without mouse click . . 38
3.2.5 Changing dimensions . . . . . . . . . . . . . . . . . . . . . 38
3.2.6 Quickly generating test data . . . . . . . . . . . . . . . . . . 38
3.2.7 Bundled examples . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.7.1 List of examples . . . . . . . . . . . . . . . . . . . . 42
3.2.7.2 Locating the examples . . . . . . . . . . . . . . . . . 44
3.2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Static, virtual, and dynamic cells . . . . . . . . . . . . . . . . . . . . 45
3.3.1 Static cell properties . . . . . . . . . . . . . . . . . . . . . . 46
3.3.2 Using virtual cells . . . . . . . . . . . . . . . . . . . . . . . 48
3.3.2.1 Changing cell data for display . . . . . . . . . . . . . 50
3.3.2.2 Provide data on demand using virtual cells . . . . . 53
3.3.3 Dynamic cell properties . . . . . . . . . . . . . . . . . . . . 54
3.3.3.1 State of the grid . . . . . . . . . . . . . . . . . . . . 54
3.3.3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.3.3.3 Color gradient . . . . . . . . . . . . . . . . . . . . . 57
3.3.3.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . 59
3.3.3.5 Mouse cursor . . . . . . . . . . . . . . . . . . . . . . 61
3.4 Using HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.4.1 Images stored in PictureContainer and GridImages . . . . . 63
3.4.2 Supported tags . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.4.3 Where to insert HTML tags . . . . . . . . . . . . . . . . . . 76
3.5 Organizing rows and columns . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1 Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1.1 Persisting column widths . . . . . . . . . . . . . . . 79
3.5.1.2 Stretching . . . . . . . . . . . . . . . . . . . . . . . 79
3.5.2 Reordering (moving) . . . . . . . . . . . . . . . . . . . . . . 81
3.5.3 Hidden columns and rows . . . . . . . . . . . . . . . . . . . 85
3.5.4 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.5 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.6 Loading and writing grid data . . . . . . . . . . . . . . . . . . . . . . 98
3.6.1 Customizing saving and loading . . . . . . . . . . . . . . . . 100
3.6.2 Creating PDF files . . . . . . . . . . . . . . . . . . . . . . . 101
3.6.2.1 Document options . . . . . . . . . . . . . . . . . . . 101
3.6.2.2 Document information . . . . . . . . . . . . . . . . 106
3.6.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . 106
3.7 Navigating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.7.1 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.7.2 Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.8 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
3.8.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.8.2 Storing and loading . . . . . . . . . . . . . . . . . . . . . . 130
3.8.3 Sort styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.8.3.1 Manually specifying the cell format . . . . . . . . . 133
3.8.3.2 Custom sorting . . . . . . . . . . . . . . . . . . . . . 134
3.8.4 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.8.5 Ignoring columns . . . . . . . . . . . . . . . . . . . . . . . . 138
3.8.6 Row indexes before and after sorting . . . . . . . . . . . . . 139
3.8.7 Triggering sorting at run-time . . . . . . . . . . . . . . . . . 139
3.8.7.1 Single column . . . . . . . . . . . . . . . . . . . . . 140
3.8.7.2 Sort column sequences . . . . . . . . . . . . . . . . 140
3.8.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
3.9 Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
3.9.1 Enabling editing for all cells . . . . . . . . . . . . . . . . . . 145
3.9.2 Read-only cells . . . . . . . . . . . . . . . . . . . . . . . . . 147
3.9.3 Starting the edit process using code . . . . . . . . . . . . . . 148
3.9.4 Inplace editors . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.9.4.1 Defining an inplace editor . . . . . . . . . . . . . . . 150
3.9.4.2 Restricting the length of input . . . . . . . . . . . . 151
3.9.4.3 Using masks . . . . . . . . . . . . . . . . . . . . . . 151
3.9.4.4 Spin editors . . . . . . . . . . . . . . . . . . . . . . . 154
3.9.4.5 Combo boxes . . . . . . . . . . . . . . . . . . . . . . 156
3.9.5 Validating user input . . . . . . . . . . . . . . . . . . . . . . 160
3.10 Undo & Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

4 TDBAdvGrid: Data-aware TAdvStringGrid
4.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 169
4.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 169
4.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 169
4.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171

II Hands-on Examples

5 Assorted grid examples
5.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 175
5.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 176
5.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 178
5.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 180
5.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 184
5.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 186
5.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 188
5.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 195
5.2.1 Creating an SQLite database with Array DML . . . . . . . . 196
5.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 202
5.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 208
5.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 210
5.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 211
5.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 211
5.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 214
5.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 216
5.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 217
5.4.1 Components on the main form . . . . . . . . . . . . . . . . 219
5.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 227
5.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 230
5.4.4 Fields and properties of the main form . . . . . . . . . . . . 231
5.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 234
5.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 238
5.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 239
5.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 240
5.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 242
5.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 245
5.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247

6 Multi-tier, cross-platform development
6.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 251
6.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 252
6.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 254
6.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 256
6.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 256
6.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 258
6.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 258
6.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 260
6.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 260
6.2.1 Creating the server application . . . . . . . . . . . . . . . . 261
6.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 262
6.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 266
6.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 268
6.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 271
6.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 272
6.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 275
6.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 275
6.2.9 Implementing the service method . . . . . . . . . . . . . . . 278
6.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 280
6.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 282
6.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 283
6.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 287
6.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 292
6.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 292
6.2.13.3 Excluding methods from Swagger . . . . . . . . . . 294
6.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 295
6.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 296
6.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 298
6.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 303
6.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 304
6.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 305
6.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 305
6.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 306
6.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 306
6.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 308
6.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 311
6.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 315
6.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 316
6.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 318
6.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 318
6.5.4 Processing the result and updating the grid . . . . . . . . . 319
6.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 323
6.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 325
6.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 325
6.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 327
6.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 328
6.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 329
6.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 331
6.6.7 Evaluating the size of Web service results . . . . . . . . . . 332
6.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 337
6.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 338
6.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 340
6.7.1 Windows application vs. Windows service . . . . . . . . . . 341
6.7.2 Migrating an existing server project . . . . . . . . . . . . . . 342
6.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 342
6.7.2.2 Adding service information to the service container . 343
6.7.2.3 Starting and stopping the server . . . . . . . . . . . 346
6.7.2.4 Adding the Windows service class . . . . . . . . . . 347
6.7.2.5 Helper methods to extend framework classes . . . . 349
6.7.2.6 Updating the project source file . . . . . . . . . . . . 350
6.7.2.7 Custom Command-line switch . . . . . . . . . . . . 353
6.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 353
6.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 354
6.8.1.1 Settings for the database connection . . . . . . . . . 355
6.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 355
6.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 355
6.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 359
6.8.2 Defining the configuration service . . . . . . . . . . . . . . . 359
6.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 360
6.8.4 Implementing the configuration service . . . . . . . . . . . 361
6.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 362
6.8.5.1 Implementing the Singleton pattern . . . . . . . . . 364
6.8.5.2 Implementing methods to start and stop the data server . . . . . . . . . . . . . . . . . . . . . . . . . . 366
6.8.6 Adding services to the second XData server . . . . . . . . . 368
6.8.6.1 Updating the postal service . . . . . . . . . . . . . . 369
6.8.7 Adding start and stop to the configuration service . . . . . . 372
6.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 374
6.8.9 Using the configuration service . . . . . . . . . . . . . . . . 377
6.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 378
6.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 378
6.9.2 Data module for XData connectivity . . . . . . . . . . . . . 385
6.9.3 Initiating the connection from the main form . . . . . . . . 387
6.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 388
6.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 394
6.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 397
6.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 400
6.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 401
6.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 403
6.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 404
6.11.2 Implementing the config button . . . . . . . . . . . . . . . . 406
6.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 406
6.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 407
6.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 408
6.12.3 Implementing the service methods . . . . . . . . . . . . . . 415
6.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 420
6.13.1 Updating the service controller . . . . . . . . . . . . . . . . 420
6.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 425
6.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 434
6.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 435
6.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 435
6.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 438
6.14.1 Looking at the finished application . . . . . . . . . . . . . . 440
6.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 443
6.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 445
6.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 445
6.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 446
6.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 449
6.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451

7 Appendix
7.1 Internet Component Suite (ICS) . . . . . . . . . . . . . . . . . . . . . 453
7.1.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
7.1.2 List of components . . . . . . . . . . . . . . . . . . . . . . . 454
7.1.3 List of examples . . . . . . . . . . . . . . . . . . . . . . . . 455
7.1.4 Legal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
7.2 TColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
7.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

1 Preface 1.1 About the series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 Required programming skills . . . . . . . . . . . . . . . . . . . . . . 18
1.3 Structure of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Technical review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5 Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2 Introduction
2.1 Required licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Downloading the source code . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.1 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.3 Keyboard and mouse . . . . . . . . . . . . . . . . . . . . . . 26
2.4.4 References to other books . . . . . . . . . . . . . . . . . . . 26
2.5 Getting help reproducing the examples . . . . . . . . . . . . . . . . . 26

I VCL Grid Controls

3 TAdvStringGrid
3.1 Compatibility with Delphi versions . . . . . . . . . . . . . . . . . . . 29
3.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.1 Cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.2 Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.3 Writing text into cells . . . . . . . . . . . . . . . . . . . . . 34
3.2.4 Handling mouse clicks . . . . . . . . . . . . . . . . . . . . . 36
3.2.4.1 OnCellClick with row selection . . . . . . . . . . . . 36
3.2.4.2 Determine selected cell(s) without mouse click . . . 37
3.2.4.3 Determine selected rows(s) without mouse click . . 38
3.2.5 Changing dimensions . . . . . . . . . . . . . . . . . . . . . 38
3.2.6 Quickly generating test data . . . . . . . . . . . . . . . . . . 38
3.2.7 Bundled examples . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.7.1 List of examples . . . . . . . . . . . . . . . . . . . . 42
3.2.7.2 Locating the examples . . . . . . . . . . . . . . . . . 44
3.2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Static, virtual, and dynamic cells . . . . . . . . . . . . . . . . . . . . 45
3.3.1 Static cell properties . . . . . . . . . . . . . . . . . . . . . . 46
3.3.2 Using virtual cells . . . . . . . . . . . . . . . . . . . . . . . 48
3.3.2.1 Changing cell data for display . . . . . . . . . . . . . 50
3.3.2.2 Provide data on demand using virtual cells . . . . . 53
3.3.3 Dynamic cell properties . . . . . . . . . . . . . . . . . . . . 54
3.3.3.1 State of the grid . . . . . . . . . . . . . . . . . . . . 54
3.3.3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.3.3.3 Color gradient . . . . . . . . . . . . . . . . . . . . . 57
3.3.3.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . 59
3.3.3.5 Mouse cursor . . . . . . . . . . . . . . . . . . . . . . 61
3.4 Using HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.4.1 Images stored in PictureContainer and GridImages . . . . . 63
3.4.2 Supported tags . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.4.3 Where to insert HTML tags . . . . . . . . . . . . . . . . . . 76
3.5 Organizing rows and columns . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1 Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.5.1.1 Persisting column widths . . . . . . . . . . . . . . . 79
3.5.1.2 Stretching . . . . . . . . . . . . . . . . . . . . . . . 79
3.5.2 Reordering (moving) . . . . . . . . . . . . . . . . . . . . . . 81
3.5.3 Hidden columns and rows . . . . . . . . . . . . . . . . . . . 85
3.5.4 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.5 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.6 Loading and writing grid data . . . . . . . . . . . . . . . . . . . . . . 98
3.6.1 Customizing saving and loading . . . . . . . . . . . . . . . . 100
3.6.2 Creating PDF files . . . . . . . . . . . . . . . . . . . . . . . 101
3.6.2.1 Document options . . . . . . . . . . . . . . . . . . . 101
3.6.2.2 Document information . . . . . . . . . . . . . . . . 106
3.6.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . 106
3.7 Navigating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.7.1 Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.7.2 Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.8 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
3.8.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.8.2 Storing and loading . . . . . . . . . . . . . . . . . . . . . . 130
3.8.3 Sort styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.8.3.1 Manually specifying the cell format . . . . . . . . . 133
3.8.3.2 Custom sorting . . . . . . . . . . . . . . . . . . . . . 134
3.8.4 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.8.5 Ignoring columns . . . . . . . . . . . . . . . . . . . . . . . . 138
3.8.6 Row indexes before and after sorting . . . . . . . . . . . . . 139
3.8.7 Triggering sorting at run-time . . . . . . . . . . . . . . . . . 139
3.8.7.1 Single column . . . . . . . . . . . . . . . . . . . . . 140
3.8.7.2 Sort column sequences . . . . . . . . . . . . . . . . 140
3.8.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
3.9 Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
3.9.1 Enabling editing for all cells . . . . . . . . . . . . . . . . . . 145
3.9.2 Read-only cells . . . . . . . . . . . . . . . . . . . . . . . . . 147
3.9.3 Starting the edit process using code . . . . . . . . . . . . . . 148
3.9.4 Inplace editors . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.9.4.1 Defining an inplace editor . . . . . . . . . . . . . . . 150
3.9.4.2 Restricting the length of input . . . . . . . . . . . . 151
3.9.4.3 Using masks . . . . . . . . . . . . . . . . . . . . . . 151
3.9.4.4 Spin editors . . . . . . . . . . . . . . . . . . . . . . . 154
3.9.4.5 Combo boxes . . . . . . . . . . . . . . . . . . . . . . 156
3.9.5 Validating user input . . . . . . . . . . . . . . . . . . . . . . 160
3.10 Undo & Redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

4 TDBAdvGrid: Data-aware TAdvStringGrid
4.1 How is data linked to the grid? . . . . . . . . . . . . . . . . . . . . . 169
4.1.1 Assigning the datasource . . . . . . . . . . . . . . . . . . . . 169
4.1.2 Defining columns . . . . . . . . . . . . . . . . . . . . . . . . 169
4.2 PageMode is key! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.3 EditPostMode determines when data is posted . . . . . . . . . . . . . 171

II Hands-on Examples

5 Assorted grid examples
5.1 VCL: Loading big CSV data files asynchronously . . . . . . . . . . . . 175
5.1.1 Downloading the data . . . . . . . . . . . . . . . . . . . . . 176
5.1.2 Why we use a resource . . . . . . . . . . . . . . . . . . . . . 178
5.1.3 Adding the resource . . . . . . . . . . . . . . . . . . . . . . 180
5.1.4 Loading the resource at run-time . . . . . . . . . . . . . . . 184
5.1.5 Indicating activity . . . . . . . . . . . . . . . . . . . . . . . 186
5.1.6 Loading data asynchronously . . . . . . . . . . . . . . . . . 188
5.2 Browsing data from an SQLite database . . . . . . . . . . . . . . . . 195
5.2.1 Creating an SQLite database with Array DML . . . . . . . . 196
5.2.2 Changing the browser app to SQLite . . . . . . . . . . . . . 202
5.3 Browsing data with a filter . . . . . . . . . . . . . . . . . . . . . . . . 208
5.3.1 Populating the combo box . . . . . . . . . . . . . . . . . . . 210
5.3.2 Showing only data for one state . . . . . . . . . . . . . . . . 211
5.3.3 Initializing the user interface . . . . . . . . . . . . . . . . . 211
5.3.4 Loading data for a state . . . . . . . . . . . . . . . . . . . . 214
5.3.5 Adding eye candy . . . . . . . . . . . . . . . . . . . . . . . . 216
5.4 Using vector images in TAdvStringGrid . . . . . . . . . . . . . . . . . 217
5.4.1 Components on the main form . . . . . . . . . . . . . . . . 219
5.4.2 Application Settings . . . . . . . . . . . . . . . . . . . . . . 227
5.4.3 TIconItem: Container for icons . . . . . . . . . . . . . . . . 230
5.4.4 Fields and properties of the main form . . . . . . . . . . . . 231
5.4.5 Setting up the grid . . . . . . . . . . . . . . . . . . . . . . . 234
5.4.6 Folder selection . . . . . . . . . . . . . . . . . . . . . . . . . 238
5.4.7 Updating the image list . . . . . . . . . . . . . . . . . . . . 239
5.4.8 Loading icons from a folder . . . . . . . . . . . . . . . . . . 240
5.4.9 Loading icons stored in a ZIP archive . . . . . . . . . . . . . 242
5.4.10 Export to Microsoft Excel . . . . . . . . . . . . . . . . . . . 245
5.4.11 Reacting to display resolution changes . . . . . . . . . . . . 247

6 Multi-tier, cross-platform development
6.1 Building the database . . . . . . . . . . . . . . . . . . . . . . . . . . 251
6.1.1 Creating the database . . . . . . . . . . . . . . . . . . . . . 252
6.1.2 Postal code table . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 254
6.1.2.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 254
6.1.2.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 256
6.1.2.4 Creating the table . . . . . . . . . . . . . . . . . . . 256
6.1.2.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3 Country codes . . . . . . . . . . . . . . . . . . . . . . . . . 257
6.1.3.1 Source . . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.2 Usage restrictions . . . . . . . . . . . . . . . . . . . 258
6.1.3.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . 258
6.1.3.4 Creating the table . . . . . . . . . . . . . . . . . . . 258
6.1.3.5 Sample data . . . . . . . . . . . . . . . . . . . . . . 260
6.2 TMS XData: Web services . . . . . . . . . . . . . . . . . . . . . . . . 260
6.2.1 Creating the server application . . . . . . . . . . . . . . . . 261
6.2.2 Class for Web service data . . . . . . . . . . . . . . . . . . . 262
6.2.3 Database access . . . . . . . . . . . . . . . . . . . . . . . . . 266
6.2.4 Providing a connection . . . . . . . . . . . . . . . . . . . . . 268
6.2.5 Using the GetConnection method . . . . . . . . . . . . . . . 271
6.2.6 Querying the database . . . . . . . . . . . . . . . . . . . . . 272
6.2.7 Mandatory units . . . . . . . . . . . . . . . . . . . . . . . . 275
6.2.8 Defining the service interface . . . . . . . . . . . . . . . . . 275
6.2.9 Implementing the service method . . . . . . . . . . . . . . . 278
6.2.10 Database client libraries . . . . . . . . . . . . . . . . . . . . 280
6.2.11 Adding a custom route . . . . . . . . . . . . . . . . . . . . . 282
6.2.12 Browse your services with Swagger UI . . . . . . . . . . . . 283
6.2.13 Adding documentation for Swagger UI . . . . . . . . . . . . 287
6.2.13.1 XMLDoc in Delphi . . . . . . . . . . . . . . . . . . . 292
6.2.13.2 Swagger-specific tags . . . . . . . . . . . . . . . . . 292
6.2.13.3 Excluding methods from Swagger . . . . . . . . . . 294
6.3 VCL: Implementing a desktop client for lookup . . . . . . . . . . . . 295
6.3.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 296
6.3.2 Retrieving data from the Web service . . . . . . . . . . . . . 298
6.3.3 Implementing the user events . . . . . . . . . . . . . . . . . 303
6.3.4 Customizing the grid control . . . . . . . . . . . . . . . . . 304
6.3.5 A word on T(Virtual)ImageList . . . . . . . . . . . . . . . . 305
6.4 FMX: Mobile app to lookup postal codes . . . . . . . . . . . . . . . . 305
6.4.1 The worst...comes first . . . . . . . . . . . . . . . . . . . . . 306
6.4.2 HTTP and HTTPS in Android apps . . . . . . . . . . . . . . 306
6.4.3 Building the user interface . . . . . . . . . . . . . . . . . . . 308
6.4.4 Retrieving data from the Web service . . . . . . . . . . . . . 311
6.5 TMS WEB Core: Web client application . . . . . . . . . . . . . . . . . 315
6.5.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 316
6.5.2 Connecting to the XData server . . . . . . . . . . . . . . . . 318
6.5.3 Calling the service method . . . . . . . . . . . . . . . . . . . 318
6.5.4 Processing the result and updating the grid . . . . . . . . . 319
6.6 VCL: Using the Web service for efficient data entry . . . . . . . . . . 323
6.6.1 Designing the user interface . . . . . . . . . . . . . . . . . . 325
6.6.2 Fields and constants in the form . . . . . . . . . . . . . . . 325
6.6.3 Initializing the form and grid . . . . . . . . . . . . . . . . . 327
6.6.4 Saving and loading the grid values . . . . . . . . . . . . . . 328
6.6.5 Setup for editing . . . . . . . . . . . . . . . . . . . . . . . . 329
6.6.6 Retrieving data from the Web service . . . . . . . . . . . . . 331
6.6.7 Evaluating the size of Web service results . . . . . . . . . . 332
6.6.8 Validation of postal codes . . . . . . . . . . . . . . . . . . . 337
6.6.9 Selection from a combo box . . . . . . . . . . . . . . . . . . 338
6.7 TMS XData: Deployment as Windows service . . . . . . . . . . . . . 340
6.7.1 Windows application vs. Windows service . . . . . . . . . . 341
6.7.2 Migrating an existing server project . . . . . . . . . . . . . . 342
6.7.2.1 Thanks to Wagner Landgraf and outlook . . . . . . . 342
6.7.2.2 Adding service information to the service container . 343
6.7.2.3 Starting and stopping the server . . . . . . . . . . . 346
6.7.2.4 Adding the Windows service class . . . . . . . . . . 347
6.7.2.5 Helper methods to extend framework classes . . . . 349
6.7.2.6 Updating the project source file . . . . . . . . . . . . 350
6.7.2.7 Custom Command-line switch . . . . . . . . . . . . 353
6.8 TMS XData: Configuration of Web Services at run-time . . . . . . . . 353
6.8.1 Settings for IPostalService . . . . . . . . . . . . . . . . . . . 354
6.8.1.1 Settings for the database connection . . . . . . . . . 355
6.8.1.2 Settings for the server . . . . . . . . . . . . . . . . . 355
6.8.1.3 TServerSettings class . . . . . . . . . . . . . . . . . 355
6.8.1.4 Server status . . . . . . . . . . . . . . . . . . . . . . 359
6.8.2 Defining the configuration service . . . . . . . . . . . . . . . 359
6.8.3 Models, services, and endpoints . . . . . . . . . . . . . . . . 360
6.8.4 Implementing the configuration service . . . . . . . . . . . 361
6.8.5 Adding a second XData server . . . . . . . . . . . . . . . . . 362
6.8.5.1 Implementing the Singleton pattern . . . . . . . . . 364
6.8.5.2 Implementing methods to start and stop the data server . . . . . . . . . . . . . . . . . . . . . . . . . . 366
6.8.6 Adding services to the second XData server . . . . . . . . . 368
6.8.6.1 Updating the postal service . . . . . . . . . . . . . . 369
6.8.7 Adding start and stop to the configuration service . . . . . . 372
6.8.8 Automatic reservation of endpoints . . . . . . . . . . . . . . 374
6.8.9 Using the configuration service . . . . . . . . . . . . . . . . 377
6.9 TMS WEB Core: Building a Web interface . . . . . . . . . . . . . . . 378
6.9.1 Designing the main form . . . . . . . . . . . . . . . . . . . . 378
6.9.2 Data module for XData connectivity . . . . . . . . . . . . . 385
6.9.3 Initiating the connection from the main form . . . . . . . . 387
6.9.4 Retrieving the server configuration . . . . . . . . . . . . . . 388
6.9.5 Sending settings to the server . . . . . . . . . . . . . . . . . 394
6.9.6 Starting the service . . . . . . . . . . . . . . . . . . . . . . . 397
6.9.7 Stopping the service . . . . . . . . . . . . . . . . . . . . . . 400
6.10 Adding a Web server to an XData server . . . . . . . . . . . . . . . . 401
6.11 VCL: Updating the user interface with vectors . . . . . . . . . . . . . 403
6.11.1 Adding vector images . . . . . . . . . . . . . . . . . . . . . 404
6.11.2 Implementing the config button . . . . . . . . . . . . . . . . 406
6.12 TMS XData: Monitoring critical server parameters . . . . . . . . . . . 406
6.12.1 Hardware being monitored . . . . . . . . . . . . . . . . . . 407
6.12.2 Getting the hardware info . . . . . . . . . . . . . . . . . . . 408
6.12.3 Implementing the service methods . . . . . . . . . . . . . . 415
6.13 TMS WEB Core: Adding monitoring to the Web client . . . . . . . . . 420
6.13.1 Updating the service controller . . . . . . . . . . . . . . . . 420
6.13.2 Adding the popup window . . . . . . . . . . . . . . . . . . . 425
6.13.3 Appearance of the caption . . . . . . . . . . . . . . . . . . . 434
6.13.4 Closing the pop-up window . . . . . . . . . . . . . . . . . . 435
6.13.5 Showing the pop-up window . . . . . . . . . . . . . . . . . 435
6.14 TMS Miletus: Creating a Windows client . . . . . . . . . . . . . . . . 438
6.14.1 Looking at the finished application . . . . . . . . . . . . . . 440
6.14.2 Create a new TMS Miletus application . . . . . . . . . . . . 443
6.14.3 Updating the project file . . . . . . . . . . . . . . . . . . . . 445
6.14.4 Migrating the service controller . . . . . . . . . . . . . . . . 445
6.14.5 Migrating the main form . . . . . . . . . . . . . . . . . . . . 446
6.14.6 Updating the pop-up window . . . . . . . . . . . . . . . . . 449
6.14.7 Running the application . . . . . . . . . . . . . . . . . . . . 451

7 Appendix
7.1 Internet Component Suite (ICS) . . . . . . . . . . . . . . . . . . . . . 453
7.1.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
7.1.2 List of components . . . . . . . . . . . . . . . . . . . . . . . 454
7.1.3 List of examples . . . . . . . . . . . . . . . . . . . . . . . . 455
7.1.4 Legal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
7.2 TColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
7.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459