Showing posts with label OpenSource. Show all posts
Showing posts with label OpenSource. Show all posts

Tuesday, January 8, 2019

Delphi Flux application architecture

A good application architecture

Finding a good application architecture is not easy, but defining an architecture for your application is important: like it or not, every application is going to have an architecture.
There is no such thing as the Best Architecture, but there is the Best Architecture for your current application! (finish the project on time, with quality, less bugs as possible - no bugs preferred :) - and easy collaboration with your teammates).
Flux is the application architecture that Facebook uses to structure client-side web applications, is very simple to understand and there is almost no code for it. It's just a way to do things.
It’s a Clean Architecture so it’s not intended only for web apps, but its features and simplicity will allow us to adapt it very well to other kind of projects.
I believe Flux is very good choice.

Delphi Flux

Base Flux concepts, I created a project on Github Delphi-Flux-Seed. This project is an application skeleton to apply Flux concepts in Delphi applications. You can use it to quickly bootstrap your Delphi application. 

About Delphi Flux I held a session at CodeRage 2018, so you can watch the replay of that session at this link. Here are the slides of my presentation at CodeRage 2018:

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 

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!

Sunday, June 25, 2017

Simple retry mechanism in Delphi

Hi all,
I want to share with you a nice unit that provide a retry pattern. How many times you want to execute some code and, if that method throws an exception, you want to retry executing it several times? For example when you try to connect to a service or network resource or a database. The operation was something that failed frequently enough that it was necessary sometimes to retry until it succeeded. With this unit you enable an application to handle transient failures by transparently retrying a failed operation.
Here is the RetryHelperU:
The snippet is very simple to understand: you have to specify the number of retries, the milliseconds between each retry and a TProc that represents the operation to do.
I also added this project to my Delphi Demos repository.
I hope it will be useful!

Tuesday, April 11, 2017

Delphi and Firebase: Remote configuration

Hi all,
as you know Firebase is a backend service that include a data storage service. One of common example of this kind of service is Remote Configuration, that allows you to change the behavior or appearance of your app (ex. change the welcome message of your app) without changing the app source code.
I've just updated the Firebase4Delphi repository with a new demo : RemoteConfigDemo.
In this demo I implemented a mechanism to allow to change the behavior and appearance of your app without publishing an app update.
The process is very simple, you have to:
  1. create a JSON Object in your console project that represents the app configuration
  2. Wraps that configuration in your app
  3. Check when configuration change and communicate it to your app
In this demo you have the possibilities to change the style of your application, according to OS, at run time.

Firebase Console 

AquaGraphite.style configured at run-time
RubyGraphite.style configured at run-time




ASAP I'll post a short video to show the power of this feature.

Wednesday, September 28, 2016

ITDevCon 2016 - Next Week

Hi all,
next week there will be ITDevCon2016 and I'm looking forward to it every time I read the agenda!



Here some info that I hope you appreciate as much as I did:
  • Speakers
    • 15 speakers from all over the world (from Brazil to Slovenia, from Germany to Italy)
    • Almost all the speakers are Embarcadero MVP
  • Topics
    • Last Delphi features
    • Spring4D
    • DelphiMVC framework
    • IoT
    • Delphi and Arduino Integration
    • Firebird 3.x
    • MongoDB
    • Redis
    • Web development with Delphi and most famous web framework (Angular, React)
    • Mobile development
    • Patterns and best practices (REST - Unit Testing - EDA )

There are all prerequisites to be a great conference! 
You cannot miss it !!

Saturday, June 18, 2016

Simple chat messaging system with Delphi and Firebase

Hi all,
some time ago I posted about my open source project: Firebase4Delphi. Well, Firebase was acquired by Google and in Google I/O 2016 was showed very interesting news and new features (more info here ). My project provide a REST facade to consume FIREBASE RealTime Database API.
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data. - Firebase Realtime Database Documentation
In my project there is a sample application about a Chat messaging system. If you enjoy Firebase program (https://console.firebase.google.com/), you are able to create your first Firebase project! See the online documentation to undestand how Firebase works.
Once you create your application you can start to use the Chat Messaging sample, it's very easy if you follow these steps:
  1. Create a clone of Firebase4Delphi project (or download it)
  2. Open Firebase4DelphiChatDemo.dproj
  3. Deploy the app on your favorite Target Platoform (Windows, Mac, Android, iOS)
  4. Once application started, put in the settings tab (Fig 1) the URL provided by Firebase Realtime Database related to your project (Fig 2) , adding the demo name "chatdemo" as REST parameter
  5. Choose a username
  6. Click Start Chat button
Fig 1:

Fig 2:

















Monday, February 29, 2016

DEB an Event Bus framework for Delphi

Hi all,
I have just started a new open source project: Delphi Event Bus a.k.a. DEB. As the title suggest DEB is an event bus framework based on publish/subscribe mechanism. It was inspired by EventBus framework for the Android platform.

How it works

DEB is designed to decouple different parts/layers of your application while still allowing them to communicate efficiently. The really exciting feature of this framework is that you can choose the delivery mode of the events: in the Main Thread or a Background thread.



Simply put the Subscribe attribute on your subscriber method you are able to receive a specific event, and by specifying the TThreadMode in attribute you can choose the context where to deliver the event.
For example, if you have to interact with the UI EventBus can deliver events in the main thread or If your subscriber does long running tasks (HTTP request), EventBus can also use background threads to avoid UI blocking. Regardless where an event was posted the EventBus will manage Thread synchronization, so you can deliver an Event in the MainThread and the subscriber will receive it on a background thread and viceversa.

Show me the code


Support

  • DEB is a 100% ObjectPascal framework so it works on VCL and Firemonkey
  • It works with DelphiXE7 and major
  • It should be works fine also on AppMethod

Currently, the project consists in a simple getting started guide, 2 great samples and a suite of unit tests. There is a lot of work to do, so any contributor is welcome. The project is hosted on github and here there is the link. I hope you are excited as much as I am about this project!

Stay tuned!

Sunday, January 10, 2016

New Delphi Demos repository

Hi all,
I have created a new repository on GitHub to keep all interesting Delphi demo that I have figured out. Here the link to repository. This is also a way to share the code with you, so it can be improved. The first project pushed is LocationSensorPatch, relative to previous post. I will put all my demo ASAP.

Monday, June 1, 2015

Firebase4Delphi - A new open source project

Hi all,
I have just started a new open source project on github: Firebase4Delphi. For those that don't know Firebase, it's a backend service: including data storage, user authentication, static hosting, and more. Go here for more info https://www.firebase.com/ . The purpose of this project is provide a REST wrapper (facade) to consume FIREBASE REST API. For now there is a client for basically interact with REST API and a ChatDemo example based on the official demo (https://www.firebase.com/tutorial/#session/sf2ovtgq4ko). The project use System.Net library, so is compatible from DelphiXE8. Anyone wants to enjoy this project is welcome!

Monday, January 19, 2015

RESTAdapter: a new amazing feature in Delphi MVC Framework

RESTAdapter is a new amazing feature of the famous Delphi MVCFramework (DMVCFramework for short). DMVCFramework (as you know) is a powerful framework for web solution in Delphi that respect the MVC pattern and reach RMM Level 3! Above there is a link to the site project (if you want more info about this wonderful framework). Ok, let's go ahead. What is RESTAdapter? RESTAdapter turn a Delphi Interface into your REST API. In practice you can declare an interface that represents your REST API and the RESTAdapter does all work for you. Below a mini guide on how it works:
  

  [Headers('User-Agent', 'RESTAdapter-Test')]
   IRESTAPIService = interface(IInvokable)
    ['{58B9FA23-92F4-4B8E-814B-05232F32A41F}']

    [RESTResource(HttpGet, '/persons')]
    [MapperListOf(TPerson)]
    function GetListPerson: TObjectList<tperson>;

    [RESTResource(HttpGet, '/persons/{personid}')]
    function GetPersonByID([Param('personid')] APersonID: integer): TPerson;

    [RESTResource(httpPOST, '/persons')]
    function SavePerson([Body] ABody: TPerson): TPerson;

  end;

The RestAdapter class generates an implementation of the IRESTAPIService
interface:

  
  RESTAdapter := TRESTAdapter<IRESTAPIService>.Create; 
  RESTAPIService := RESTAdapter.Build('localhost', 9999);
  Person := RESTAPIService.GetPersonByID(1);

Use RTTI Attributes to describe the REST request:
  • RESTResource: to describe URI and REST verb of resource
  • Headers: a key-value pair that represents a Header of HTTP request
  • MapperListOf: to specify the Object Type of the List
  • Param: to specify that a method parameter is a param of HTTP Request
  • Body: to specify that a method parameter is the body of HTTP Request
The TRESTAdapter class inherits from TVirtualInterface. TVirtualInterface doesn't behave like an ordinary class, each instance has an associated reference counter to automatically free itself. In practice there isn't need to free the RESTAdapter object.

In the DMVCFramework samples folder, in particularly "wincellarclientRESTAdapter" you can find a real work example. 

I hope you enjoy it!