Blog
All Blog Posts | Next Post | Previous PostIntroducing the myCloudData REST Client for Delphi & C++Builder
Friday, December 16, 2016
We are very excited to announce the launch of our new open-source myCloudData.net REST client for Delphi & C++Builder. The myCloudData REST Client is completely free and open-source and hosted on Github, this means that you can freely use or customize the code for your commercial or hobby projects.Our goal was to provide you with an easy way of using the myCloudData.net service in all your applications, without having to worry about all the difficulties that come with integrating with a complex REST service.
The myCloudData REST Client takes care of handling the HTTP requests, the parsing of the JSON responses and the OAUTH2 authentication. All you have to do is drag the component on to your form and you can start using your cloud databases as they were local databases.
The library is developed from the ground up and is based on the REST technology that is included in RAD Studio 10.1 Berlin. It can be used with your Delphi, C++Builder, RAD Studio 10.1 Berlin IDE as-is, no need to install extra commercial libraries. There is a REST client for VCL applications (for Win32/Win64) and FMX applications (for Win32/Win64/iOS/macOS/Android)
To get you started, here are some highlights of commonly used patterns in consuming structured cloud data storage via myCloudData.net.
Some simple code examples
Creating a table
Typically, at the startup of your application, you'll want to check if the table you want to work with already exists on the current myCloudData account. The code example below does just that, it looks for the table on theTables
property of the myCloudData component and if it isn't found it will create the table with all the necessary fields.
var LContactsTable : TmyCloudDataTable; begin // Search for an existing table LContactsTable := MyCloudData.Tables.GetTableByName('MyApplication_Contacts'); if LTableName = nil then begin // Create the table LContactsTable := MyCloudData.Tables.CreateTable('MyApplication_Contacts'); // Start adding your fields: LContactsTable.Fields.Add('ID', ftInteger); LContactsTable.Fields.Add('Name', ftWideString, 30); LContactsTable.Fields.Add('EmailAddress', ftWideString, 50); LContactsTable.Fields.Add('CountryCode', ftWideString, 2); // Save the fields to the myCloudData.net service LContactsTable.Fields.Save(); end; // You can start working with the table here. end;
Working with the entities
Once you have your table, let's add some data to it. The next example shows how you can insert a new entity and populate its fields.var LContact : TmyCloudDataEntity; begin // Create the new entity on the table LContact := LContactsTable.Entities.CreateEntity(); // Populate the fields on the entity LContact.SetValue('ID', 285); LContact.SetValue('Name', 'John Doe'); LContact.SetValue('EmailAddress', 'johndoe@gmail.com'); LContact.SetValue('CountryCode', 'USA'); // Save the entity to the myCloudData.net service LContactsTable.Entities.Save; end;
The following code shows you how to query the table and retrieve existing entities.
// Optionaly set the page size and index LContactsTable.PageSize = 20; LContactsTable.PageIndex = 0; // Optionaly add one or more filter conditions LContactsTable.Filters.Add('Name', coLike, 'John'); LContactsTable.Filters.Add('Email', coEndsWith, 'gmail.com', loAnd); // Optionaly add one or more sorting statements LContactsTable.Sorting.Add('Company', soAscending); LContactsTable.Sorting.Add('Name', soDescending); // execute the query LContactsTable.Query(); // now you can use the result of that query by accessing the Entities property for LContact in LContactsTable.Entities do begin ContactsListBox.items.Add(LContact.GetValue('Name')); end;
Blobs
All the above examples work for both the free and the subscription accounts on myCloudData.net.However, working with blob fields requires you to be connected with a subscription account.
To avoid unexpected behaviour, you'll always want to check if the current user can use the blob feature before actually creating or using a blob field.
This example shows how you can create a blob field in a table.
// Check if the current user can use blob fields if MyCloudData.CurrentUser.CanUseBlobFields; then begin // Add the field to the table LContactsTable.Fields.AddOrUpdate('Picture', ftBlob); end;
Saving a new file to the blob field can be done as follows.
var LPictureField : TmyCloudDataBlob; begin // Fetch the Entities on the table LContactsTable.Query(); // Get an entity by its ID LContact := LContactsTable.Entities.GetEntity(LEntityId); // Get the blob field LPictureField := LContact.GetBlobField('Picture'); // Save a new image LPictureField.FromFile('c:path oyourimage.jpg'); end;
We invite you to start experimenting with these new free REST client components and we are very eager to learn how these will be used to build your creative & amazing apps with myCloudData.net and RAD Studio 10.1 Berlin.
Please take a look at the Github repository and let us know what you think!
Bruno Fierens
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post