Monday, August 6, 2018

Delphi Cookbook - Third Edition

This book is the 3rd edition of the Delphi Cookbook serie: Delphi Cookbook is a best sellers for PacktPub (the editor) in its category, so the editor decided to ask me a 3rd edition in co-authorimg with Daniele Teti (author of the 2 previous versions). So here it is!

What's new

In this third edition we wanted to add content to keep the book updated with emerging technologies and new features made available by Delphi: there are 2 chapters completely new, one for Linux Development and one for Integration with IoT, added useful chapters on FireDAC and RTTI attributes. Furthermore, this edition contains all the recipes from the previous editions updated to the new Delphi 10.2 Tokyo: reaching 780 pages for 78 recipes!

This book today lets you learn all the development possibilities offered by Delphi: cross-platform (Firemonkey), mobile applications (Android and iOS), server-side programs (Linux and Windows), integration with IoT, working with data (FireDAC, JSON, XML) and so on...

Topics of the book

  • Develop visually stunning applications using FireMonkey
  • Deploy LiveBinding effectively with the right OOP approach
  • Working with data (JSON, XML)
  • Design, develop and deploy server-side programs to serve RESTful web services (Linux and Windows) and provide data to your mobile apps
  • Use well-defined GUI design patterns to build mobile applications that provide a great user experience
  • Extremely useful recipes on FireDAC database access framework
  • Build mobile apps that read data from a remote server efficiently
  • Call the platform native API on Android and iOS even for an unpublished API
  • Manage software customization for your customer by making better use of an extended        RTTI
  • Implement the most popular design pattern without wasting too much time on debugging and bug fixing
  • Enrich your knowledge of Delphi deepening the libraries made available
  • Integrate your applications with Internet of Things

It is not an introductory book, you will not find any “Introduction to the Object Pascal language”, however the majority of the chapters are not too complex and can be grasped also by the new Delphi programmers.

Another interesting thing is that thanks to the release of the Delphi Community Edition (you do not know what it is ?? go here ...) all chapters except chapters 6 and 7 can be addressed through the use of this free version. For chapters 6 and 7, as it is Linux and server-side development, the Enterprise version of Delphi is required.

Where to buy

The book is available for sale on the editor website and on Amazon.

PacktPub (Official book page)


Amazon


GitHub repo for recipes code


Table of contents


Chapter 1: Delphi Basics

  • Changing your application's look and feel with VCL styles
  • Changing the style of your VCL application at runtime
  • Customizing TDBGrid
  • Using owner-draw combos and listboxes
  • Making an owner-draw control aware of the VCL styles 
  • Creating a stack of embedded forms 
  • Manipulating JSON 
  • Manipulating and transforming XML documents 
  • I/O in the 21st century – knowing the streams 
  • Creating a Windows Service 
  • Using the TService.LogMessage method 
  • Be coherent with the Windows look and feel using TTaskDialog 
  • The amazing TFDTable – indices, aggregations, views, and SQL 
  • ETL made easy – TFDBatchMode 
  • Data integration made easy – TFDLocalSQL 


Chapter 2: Becoming a Delphi Language Ninja 

  • Fun with anonymous methods – using higher-order functions 
  • Writing enumerable types 
  • Using enumerable types to create new language features 
  • RTTI to the rescue – configuring your class at runtime 
  • Duck typing using RTTI 
  • BOs validation using RTTI attributes 
  • Creating helpers for your classes 


Chapter 3: Knowing Your Friends – The Delphi RTL

  • Checking strings with regular expressions 
  • Consuming RESTful services using native HTTP(S) client libraries 
  • Coping with the encoded internet world using System.NetEncodings 
  • Saving space using System.Zip 
  • Decoupling your code using a cross-platform publish/subscribe mechanism


Chapter 4: Going Cross-Platform with FireMonkey

  • Giving a new appearance to the standard FireMonkey controls using styles 
  • Creating a styled TListBox 
  • Impressing your clients with animations 
  • Using master/details with LiveBindings 
  • Showing complex vector shapes using paths 
  • Using FireMonkey in a VCL application 
  • Reinventing your GUI, also known as mastering Firemonkey controls, shapes, and effects 


Chapter 5: The Thousand Faces of Multithreading

  • Synchronizing shared resources with TMonitor 
  • Talking with the main thread using a thread-safe queue 
  • Synchronizing multiple threads using TEvent 
  • Communication made easy with Delphi Event Bus 
  • Displaying a measure on a 2D graph like an oscilloscope 
  • Using the Parallel Programming Library in the real world: Tasks 
  • Using the Parallel Programming Library in the real world: Futures 
  • Using the Parallel Programming Library in the real world: Parallel For/Join 


Chapter 6: Putting Delphi on the Server 

  • Developing web client JavaScript applications with WebBroker on the server 
  • Converting a console application into a Windows service 
  • Serializing a dataset to JSON and back 
  • Serializing objects to JSON and back using RTTI 
  • Sending a POST HTTP request for encoding parameters 
  • Implementing a RESTful interface using WebBroker 
  • Controlling remote application using UDP 
  • Using app tethering to create a companion app 
  • Creating DataSnap Apache modules 
  • Creating WebBroker Apache modules 
  • Using native HTTP(S) client libraries 
  • Logging like a pro using LoggerPro 


Chapter 7: Linux Development 

  • Creating Linux TCP/IP servers
  • How to correctly handle Linux signals
  • How to build a modern Linux daemon 
  • Building a TCP/IP Linux server and daemonizing it 
  • Building a RESTFul server for Linux 
  • Building a complete RESTful server with database access and web client interface 
  • Creating WebBroker Apache modules for Linux 


Chapter 8: Riding the Mobile Revolution with FireMonkey

  • Taking a photo, applying effects, and sharing it 
  • Using TListView to show and search local data 
  • Using SQLite databases to handle a to-do list 
  • Do not block the main thread! 
  • Using a styled TListView to handle a long list of data 
  • Customizing the TListView 
  • Taking a photo and location and sending it to a server continuously 
  • Talking with the backend 
  • Making a phone call from your app 
  • Tracking the application's life cycle 
  • Building your own SMS sending service with the REST API 


Chapter 9: Using specific platform features

  • Using Android SDK Java classes 
  • Using iOS Objective-C SDK classes
  • Displaying PDF files in your app 
  • Sending Android Intents 554
  • Letting your phone talk – using the Android TextToSpeech engine 
  • Using Java classes in Android apps with Java2OP 
  • Doing it in the background, the right way – Android services 


Chapter 10: Delphi and IoT 

  • How to blink an LED using Arduino 
  • How to drive multiple relays with Arduino and Delphi
  • Reading data from Arduino 
  • How to blink an LED using Raspberry Pi 
  • How to drive multiple relays with Raspberry Pi and Delphi 
  • Reading data from Raspberry PI 

Monday, November 6, 2017

CodeRage XII: How to develop a simple recommender system






Tomorrow November 7th will see the 12th edition of Embarcadero's yearly online conference, called "CodeRage".

The conference, as always, respects the high quality standards:
Furthermore two guess industry luminaries will be giving sessions, Robert Martin (aka Uncle Bob) is speaking on "The Clean Coder - An Introduction to Software Professionalism" and Steven McConnell (of "Code Complete" fame) is speaking on "Managing Technical Debt".

You cannot miss it!!


You can see the full program at:  https://community.embarcadero.com/blogs/entry/coderage-xii-sessions-and-schedule.
I'm very excited because it's the first time that I will participate in the conference as speaker!
I’ll be talking at CodeRage XII about "How to develop a simple recommender system". What do Netflix, Amazon, Google and Facebook have in common? An efficient system of recommendations.
In this session I'll show how to implement a simple system of recommendations with Delphi and Redis ... in a very simple way!

Based on this work, a new product is coming to predict what you customer want! Because knowing users to propose the right product for each of them is crucial in all types of sales.
If you are interested contact me or stay tuned on bit Time Professionals.

Sunday, September 3, 2017

Delphi Entities Validators

How many of you use business objects in your applications?
How many of you use an ORM ?
In this case... how do you validate entities in your applications ?
  1. In a not very elegant way 
  2. The classic is IsValid() method on BO
  3. Something else?
  4. Validation inside or outside entities?
  5. How about different context?
Entity validation can be a tricky beast! From bit Time Professionals Lab... Delphi Entities Validators ! It is a small framework that provides an easy and ready-to-use interface for entities validation.
You can achieve Entities validation in three ways:

  1. Simple validation
  2. Attribute validation
  3. Container validation
The innovative solution of this framework is the Context: in the most case when you have to validate an Entity you have a class explosion for different situations. For example if you have to validate an entity that represents a User you have different Object classes for different context: one class for Login, one for registration etc... because the field that you have to validate are different in these different situations. With Context, the things going to get easier because you can maintain one Object Class and choose wich fields and when to validate them.
So let's go see the code!

Simple Validation

In Simple Validation mode you have to implements the IValidator interface, that use generics, replacing the placeholder with your class. The interface provides Validate method that you must implement, and here you have to write your validation logic. This method returns an IValidationResult wich is composed by:
  • IsValid - returns a boolean that represents the success or failures validation
  • BrokenRules - returns an array of string that represents the broken rules



Attributes Validation

In Attributes Validation you can use a ready-to-use attributes to validate the field of your BO (or create yours). This is first example where Context avoids you a lot of code:


In this case the affected fields are the only that have the context 'AttributesValidation'.

Container Validation

In Container Validation you can use the Simple Validation mechanism adding all the benefits of using a container and context mechanism:


Delphi Entities Validation can be a great ally in writing code, saving you time and code!