Category Archives: Level

Articles for different levels of developers

InterBase Array Fields and FireDAC

InterBase Array Field

The IoT Award Winning database InterBase, has for a long time supported the ability to store data in an array field type. This was originally introduced as a new field type to reduce API calls and speed up data write time for a specific Boeing project many years ago. Writing each value into an array can also simplified the data model as well as benefiting database performance.

While array field in InterBase have been around for a long time, they have not aways been that easy to access from the components layer reducing their adoption.

With the growth of IoT, and the ability to store multiple data points per record becoming much more common place today, the ability to work with data in the InterBase array field type using FireDAC components has been added to 10.1 Berlin.

Explore the sample in depth, and get the link the sample below. Continue reading InterBase Array Fields and FireDAC

Swagger / YAML and self documenting RESTful API’s

Get your Swagger on with Delphi

So you want to build a new REST server (using Delphi or C++) and want it to become really popular and easily used by other developers. Imagine….

  • Your building a new REST server,
  • You have to document the API’s
  • You have to keep the documentation updated
  • To aid adoption of your services you want to create examples for other developers to connect into your server quickly

With the release of RAD Studio 10.1 Berlin, it is now possible to do all the above thanks to the new documentation attributes used in EMS packages that create YAML documentation that can be used with Swagger.

What is YAML?

YAML: (rhymes with “camel”) YAML Ain’t Markup Language

In short, YAML is a human friendly data serialization standard for all programming languages that is a subset of JSON.

Both JSON and YAML aim to be human readable data interchange formats. However, JSON and YAML have different priorities. JSON’s foremost design goal is simplicity and universality. Thus, JSON is trivial to generate and parse, at the cost of reduced human readability. It also uses a lowest common denominator information model, ensuring any JSON data can be easily processed by every modern programming environment.

In contrast, YAML’s foremost design goals are human readability and support for serializing arbitrary native data structures. Thus, YAML allows for extremely readable files, but is more complex to generate and parse. In addition, YAML ventures beyond the lowest common denominator data types, requiring more complex processing when crossing between different programming environments.

YAML can therefore be viewed as a natural superset of JSON, offering improved human readability and a more complete information model. This is also the case in practice; every JSON file is also a valid YAML file. This makes it easy to migrate from JSON to YAML if/when the additional features are required.

What is Swagger?

Swagger is a simple yet powerful representation of your RESTful API, and as part of the open tools initiative (joining November 2015) it is backed by members such as Microsoft, Google, PayPal and IBM.

Using a YAML document, you can create Swagger instance of your API.

With the largest ecosystem of API tooling on the planet, thousands of developers are supporting Swagger in almost every modern programming language and deployment environment making it a great choice to make your REST server easily integrated and used by others.

With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability.

Creating YAML with Delphi / C++ Builder

To gain the benefits of Swagger you need to create the YAML documentation; this is achieved using a number of new attributes defined on the custom API’s you are creating. The three core Custom API Documentation attributes are:

In addition there are two additional documentation elements that allow you to define EndPointObjects that are used by your API. This way you define structures that are returned, rather than just returning simple types.

Custom API Documentation Sample

With Rad Studio 10.1 Berlin, in the samples, there is a new demo that covers the above custom api documentation attributes. If you want to open it in the IDE, choose “Open a sample project” and browse to the following folder and open the APIDocDelphiAttributes.bpl package (cpp equivalents also available, swap Delphi for CPP in names).

 \Samples\Delphi\Database\EMS\APIDocAttributes

As this sample uses InterBase, you need to make sure you have started InterBase. If its not running, use the IBServerManager to make sure its running. 

Rather than cover each of the attributes here, and repeat the documentation, I’ll leave you explore the links above to read up on these attributes, instead I want to use this sample to explore the YAML using Swagger UI, but first lets get the YAML document by running the sample.

Getting YAML from EMS Sample

Compile and run (F9) the sample project and choose Open Browser. You should now see a call to http://localhost:8080/version showing version 2.1 or higher.EMS Version

To get the documentation from the server, navigate to http://localhost:8080/api where you will see the different documentation types supported. EMS API

This shows 2 currently. apidoc.yaml and apidoc.json. Add these to the end of the API url to see how they look. e.g. http://localhost:8080/api/apidoc.yaml

EMS APIDoc YAML
http://localhost:8080/api/apidoc.yaml returning YAML from use with Swagger from EMS

YAML to Swagger UI

So you have a YAML document.. now what? Swagger UI is a great tool for reading the YAML document and giving you interactive HTML documentation for your RESTful API.

You can download the latest Swagger UI from GitHub onto your development machine https://github.com/swagger-api/swagger-ui

Download Swagger UI
Download Swagger UI

Unzip the download on your development machine / vm. In there locate the dist folder and open the index.html

A note on CORS

Now before we go any further, your need to be aware of CORS – Cross Origin Resource Sharing. In short, because we will want to enable PUT, POST, DELETE from outside the core domain, we need to allow CORS (or you will not be able to call EMS)

You can either update the EMS configuration to allow CORS or install the following google chrome plugin. If you install the plugin, once you have the SwaggerUI index.html page open, you need to make sure its enabled. (i’ve sometimes found I’ve had to disable and re-enable it to get it to work).

Enabling CORS using Google Chrome Plugin
Enabling CORS using Google Chrome Plugin

Loading the YAML into Swagger

Copy the URL for the YAML document and post it into your SwaggerUI/dist/index.html page, and choose Explore.

The sample (pet store) documentation in SwaggerUI will now be replaced with the documentation form the EMS server.

You can now browse and invoke the API calls directly from the SwaggerUI interface. The example creates a category called Sample Tag (which you can see listed) All the other categories cover the default features of EMS, including User security, and the new ThingPoint EdgeModule API’s

Visualising YAML in Swagger UI
Visualising YAML in Swagger UI

You can now explore the categories, review the documentation model that defines the structure being return (thanks to the EndPointObjectXXX attributes)Viewing Swagger UI exposed Methods

… and once you fill in any defined parameters you can “Try It Out”. This shows the URL called, and also the response body!

Trying out Swagger UI
Trying out Swagger UI

That is it! How simple to test you RESTful API than by using YAML and Swagger UI.

You can now explore Swagger.IO and learn about the other languages that you can create connections into your EMS server with 🙂

Accessing the address book on iOS and Android

Address Book development on iOS and Android

Accessing the Address Book on iOS and Android is a common request for many developers building line of business applications; quickly followed by “and how do I dial a phone number from code“. In this post I will explore how to explore the mobile Address Book using a common code base that works on iOS and Android using TAddressBook. (list to samples and documentation at the bottom of this article)

TAddressBook

With the launch of RAD Studio 10.1 Berlin, Delphi, C++ Builder,  comes a new component, TAddressBook, that enables easy access to the Address Book on iOS and Android.

The TAddressBook lives under Services section of the tool palette and consists of two and has very little in the way of Component properties. It does however have two events that are very useful, and a number of run time methods to call.

TAddressBook Component Events
TAddressBook Component Events

The two events provide notification when the address book has been changed (outside the application) and the result of the application asking for access to the address book.

Continue reading Accessing the address book on iOS and Android

Building Delphi Classes from JSON

JSON to Delphi Classes

I’m currently working on a new blog post showing how to integrate a popular REST API. One of my tasks is to convert JSON to Delphi Objects, so I need to define the Delphi class structures to work with so I can use the TJSON.JSONToObject that I covered previously. I decided to see if anyone had done work to convert JSON into Delphi classes.

Thankfully YES! I found this really handy project JsonToDelphiClass on GitHUB by . The project in covered in the post Introducing JsonToDelphiClass.

The JSON to Delphi Project is a Delphi FMX application that has a simple UI that allows you to modify the automatically created JSON class names which is pretty useful and the code worked first time when copied into my sample. (although I have more playing to do)

The JSON to Delphi tool is definitely a useful resource to work alongside the REST Debugger that you can find in the BIN directory of your RAD Studio install.

Stay tuned for the blog post when it arrives, but in the mean time, if your working with the REST components, I would recommend checking out Petar’s project along side my earlier post on Integrating Microsoft Azure Translation Services into Delphi.

 

Delphi 64bit Code

Updating 32bit code to Delphi 64bit

Ever since Delphi XE2, it has been possible to generate Delphi 64bit applications from the same code base as your traditional Windows 32bit Delphi code. The business case for 64-bit for business is covered in this tech paper The Impact of 64-bit Applications to your Company’s Bottom Line.

On the whole moving to 64bit (on iOS or Windows) is beautifully simple to achieve! It can be just as simple as adding the Delphi 64bit Windows target platform in the project manager and rebuilding the project.

My experience from talking to many developers who have moved up is that normally there are a few things to check in your code but typically its not a massive task to get compiling and ready to test.

A lot has been recorded on moving from Windows 32bit to Windows 64bit Delphi and this should be a useful summary if your just planning now moving up from older versions of Delphi to Delphi 10. If you are building iOS applications, then you will need to use the 64bit build now to get into the AppStore. Thankfully, Delphi has made the task of using 64bit very simple across all platforms and protected us from the headaches non Delphi Developers have had on the whole.

Lets start with this short video from David I who covers some the foundations in 7 minutes!

Continue reading Delphi 64bit Code

InterBase Journaling – InterBase Labs

InterBase Journaling

We (geeks) should all know that applications that run in memory run faster than those that have regular disk I/O.

Having more of the data processing in memory has a positive effect on speed and performance,  however its not without risk. As memory is transient, you are always at risk of data loss if the data in memory hasn’t been saved to disk (which is where you get the disk i/o speed degradation again.

InterBase brings together the speed of in memory data processing with the security of immediate disk I/O with InterBase Journaling. The write ahead logging enables InterBase to securely log the write transactions to the journal making the best of both worlds possible.

Using Journaling – the basics

Continue reading InterBase Journaling – InterBase Labs

LiveBindings in VCL – Part 7 – More LiveBinding Classes

In my earlier posts on Delphi Visual Live Bindings I looked at how to link to bindings via code.

There are a number of classes that help along the way but there are two specific categories of classes and that is what I want to cover in this post.

LiveBindings and List v Link

Sometimes you want to fill a list with values; sometimes you want to keep a list of values updated; this is in essence the difference between using List (e.g. TBindList, TBindGridList) and Link (e.g. TBindListLink, TBindGridLink)

TBindList will fill a list with values, if the data/objects linked to changes then the data will not update unless you manually tell the list to re-populate using the bindings FillLists property.

TBindListLink however will keep the list in sync.

Before you continue… look at the samples

I recommend playing with the “OneOfEach” sample in the samples directory.

{samples}\LiveBindings\oneofeach\vcl

Try changing the fish name in the TBindGridLink and seeing how it updates over the other tabs where the FishFacts data is used.

What is a Binding Source and how is it different to the Control?

Continue reading LiveBindings in VCL – Part 7 – More LiveBinding Classes

LiveBindings in VCL – Part 6 – Master Object, Detail TDataSet

Useful background to this post is available in post 4 (Linking to an Object for master detail) and post 5 (advanced master detail).

Filtering a TDataSet as detail of an object

Having explored how to link to a Master Detail relationship and created a funky anonymous method to return the data, I thought there is no reason why I should have to be returning linked data. The data could be from anywhere.

One example people have asked about when I’ve been at developer events is how to link an object to be the master for filtering a TDataSet… well, this actually provides a simple example for doing exactly this (as you can see in this video)

Continue reading LiveBindings in VCL – Part 6 – Master Object, Detail TDataSet