My Top 10 Aurelius Features - #3 Inheritance

Tuesday, February 21, 2017

How to talk about object-oriented programming and not consider inheritance? In my opinion is a basic "feature" of OOP. And how to talk about an ORM without supporting inheritance? I consider it so important that the simply fact that Aurelius supports it makes it my #3 of My Top 10 Aurelius Features.



It's really nice to be able to model classes and build a class hierarchy, reference classes in that hierarchy from other properties, have a true model that is not just a bunch of plain classes that map properties to database columns. Inheritance support allows you to really think in an OOP way when using an ORM.

TMS Aurelius supports two ways of persisting objects in a class hierarchy in the database:

Joined-tables strategy
Where data from each class is saved in a different database. This is the more normalized way.

Single-table strategy
Where data from all classes are saved in a single table. This is the simplest and often offers better performance.

Regardless of your choice, the facts is that Aurelius allows you to do so! Watch the video above to see how class inheritance works with TMS Aurelius, and if you want to get notified about upcoming videos, subscribe to our YouTube channel!

Wagner R. Landgraf


Bookmarks: 

This blog post has not received any comments yet.



Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
Comment:
 
Change Image
Fill in the characters from the image above:
 

All fields are required.
 



Cross platform messaging made easy with TMS MQTT

Tuesday, February 14, 2017

Last week we released a new product, TMS MQTT. MQTT is a standard lightweight machine 2 machine messaging protocol. This enables the instant exchange of binary or text messages between code running on various operating systems. To fully take advantage of this, we developed our TMS MQTT client to work in VCL Windows applications, FMX Windows, macOS, iOS and Android applications and also on Linux desktop or Linux variants such as Raspbian on Raspberry Pi via FPC/Lazarus.

On this 22th birthday of Delphi, I wanted to show you how our TMS MQTT component allows you to develop a messaging application in a real RAD way. I'll do this by implementing a chat application that allows you to chat between clients running on desktops or mobile devices. This effectively takes less than 40 lines of code using the TMS MQTT component of which 15 lines already go to inserting the chat text left and right in items of an FMX listbox and another +/- 10 lines detecting the origin of the chat text that is received to decide whether to show it left or right in the listbox. So, I'd say only about 15 lines of code effectively concern using the MQTT client to do the messaging.

For this demo, we use the Mosquitto MQTT test broker and connect to it with 2 lines of code:
begin
  TMSMQTTClient1.BrokerHostName := 'test.mosquitto.org';
  TMSMQTTClient1.Connect();
end;

Upon connecting, we subscribe to the topic /tms/chat/ that is the topic that will be used to exchange chat text between multiple clients. This takes 2 lines of code from the TMQTTClient.OnConnectedStatusChanged() event:
procedure TForm1.TMSMQTTClient1ConnectedStatusChanged(ASender: TObject;
  const AConnected: Boolean);
begin
  if AConnected then
    TMSMQTTClient1.Subscribe('/tms/chat/');
end;
To send a message, text entered in a memo control is published on this topic with one line of code:
  TMSMQTTClient1.Publish('/tms/chat/', TMSMQTTClient1.ClientID+'!'+ memo1.Lines.Text);
Here we add the unique ID of the app sending the chat text and the chat text itself.
Finally, incoming chat text on the subscribed topic is received via the TMQTTClient.OnPublishReceived() event. The unique client ID is retrieved to decide whether to put the chat text left or right of the message listbox and this is done via the code:
procedure TForm1.TMSMQTTClient1PublishReceived(ASender: TObject;
  APacketID: Word; ATopic: string; APayload: TArray);
var
  msg,orig: string;
  vp: integer;
  alright: boolean;
begin
  msg := TEncoding.UTF8.GetString(APayload);

  vp := pos('!', msg);

  if vp > 0 then
  begin
    orig := copy(msg,1,vp-1);
    alright := orig <> TMSMQTTClient1.ClientID;

    msg := copy(msg, vp + 1, Length(msg));
    AddMessage(msg, alright);
  end;
end;

And then comes the method to allows us to insert either left or right aligned text as items in an FMX listbox:
procedure TForm1.AddMessage(AMessage: string; AlignRight: boolean);
var
  li: Tlistboxitem;
begin
  li := Tlistboxitem.Create(self);
  li.StyledSettings := li.StyledSettings - [TStyledSetting.ssOther];
  li.Text := AMessage;
  li.Height := 22;
    li.VertTextAlign := TTextAlign.taTrailing;

  if AlignRight then
    li.TextAlign := TTextAlign.taTrailing
  else
    li.TextAlign := TTextAlign.taLeading;

  listbox1.AddObject(li);
end;

Compile and run this application on your operating system of choice. In my case, I did setup a small chat between the client compiled for Windows and the client deployed on an iPhone:

You can download the full source code of this FireMonkey application here.

I invite you to explore the numerous exciting capabilities of machine 2 machine messaging. Note that there are JS libs that facilitate to do MQTT messaging via websockets from a webbrowser. The demo included in the TMS MQTT download is based on messaging between a desktop or mobile client app and a web page application. With the TMS MQTT client, you can also use machine 2 machine messaging from your Raspberry Pi and send this way various sensor data captured by the Raspberry Pi to desktop or mobile apps. In a follow-up blog, we'll explain and offer such sample project.

I look forward to hear about how you will use MQTT machine 2 machine messaging in your apps or IoT projects!



Bruno Fierens


Bookmarks: 

This blog post has received 3 comments.


1. Tuesday, February 21, 2017 at 1:56:57 PM

Amazing!
Is it also possible to use the "payload", for sending binary data like pictures?

Thank you!

Matthias


2. Tuesday, February 21, 2017 at 2:41:10 PM

Hi Matthias,

Yes. that is possible!
In this example we use the publish function to send a string, but you can also pass it an array of bytes. So sending images is no problem.

Kind regards,
Nick

Nick Vierstraete


3. Tuesday, February 21, 2017 at 4:09:12 PM

Thank you!

Another nice feature would be a fully threaded component... :-)
Or is it already?

Matthias




Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
Comment:
 
Change Image
Fill in the characters from the image above:
 

All fields are required.
 



My Top 10 Aurelius Features - #4 Aurelius Dataset

Thursday, February 09, 2017

I consider Aurelius Dataset (TAureliusDataset) a hidden gem of TMS Aurelius. Well, not exactly "hidden" because it's a significant part of it to deserve its own chapter in the Aurelius documentation, but in the sense that it's different from the normal ORM "core" which is update, insert, delete, select, query, etc.. And for that it's #4 of My Top 10 Aurelius Features.



The first misunderstanding about the TAureliusDataset is confusing its usage with the regular way we use Delphi datasets. I've been in discussions in forums with people that were blaming the usage of dataset, because it's not "good practice", because logic should be in the controller/model, etc., etc..

The point is Aurelius Dataset is for data binding. It's not about retrieving data. You will retrieve data the same way with or without the dataset. Your logic, controller and model will still be isolated. But when it comes to show or edit data of an entity in a visual form, you don't have to manually do things like this:
edCustomerName.Text := Customer.Name;
edCustomerCity.Text := Customer.City;
or even worse, to populate a grid or list (pseudo-code):
Grid.Clear;
for Customer in Customers do
begin
  CurrentRow := Grid.AddRow;
  Grid.Columns[0, CurrentRow] := Customer.Name;
  Grid.Columns[1, CurrentRow] := Customer.City;
end;
that's tiresome, repetitive and not necessary with Aurelius Dataset. You just set the "data" of the dataset, which are your objects:
AureliusDataset1.SetSourceList(MyCustomerList);
or
AureliusDataset1.SetSourceObject(MyCustomer);
and you bind the dataset to data ware controls! Or to regular controls use live bindings. Or provide the dataset to some report tool.

The coolest thing about the Aurelius Dataset is that its minor features and high integration with Aurelius. It's not just a generic binder between Delphi objects and controls. But it handles smoothly a lot of specific Aurelius features like:

Nullable types
Associations and its sub-properties
Master-Detail (many-valued association as nested datasets)
Enumerated types

and provide the regular dataset mechanisms but adapted to the object-oriented approach, like:

Lookup fields
Calculated fields
Design-time support

And finally, it handles paging and fetching smoothly as well. You can have a criteria that is retrieved page by page on demand, avoiding all objects to be retrieved at once, and at the same time avoiding a cursor to be open to the database!

Watch the video above to see Aurelius Dataset in action, and if you want to get notified about upcoming videos, subscribe to our YouTube channel!

Wagner R. Landgraf


Bookmarks: 

This blog post has not received any comments yet.



Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
Comment:
 
Change Image
Fill in the characters from the image above:
 

All fields are required.
 



TMS FNC Core

Tuesday, January 31, 2017

With the 1.7.1.0 release of the TMS FNC UI Pack we have introduced a TMS FNC Core separation. This means the TMS FNC Core needs to be installed as a prerequisite in order to successfully install the TMS FNC UI Pack. Apart from this separation, the new core setup will not introduce breaking changes in your application, as the file names for both the TMS FNC Core and TMS FNC UI Pack have remained the same. The separation gives us the benefit of writing components that all rely on a single core, instead of duplicating units that offer exactly the same features in multiple component sets. All current and future TMS FNC products will build upon this common core.

Custom Component Development for FNC

Now the TMS FNC Core is released, you'll have a series of units available that can be used to write custom components yourself for our FNC framework.

[FMX.][VCL.][LCL]TMSFNCBitmapContainer.pas
[FMX.][VCL.][LCL]TMSFNCCustomComponent.pas
[FMX.][VCL.][LCL]TMSFNCCustomControl.pas
[FMX.][VCL.][LCL]TMSFNCCustomScrollControl.pas
[FMX.][VCL.][LCL]TMSFNCGraphics.pas
[FMX.][VCL.][LCL]TMSFNCGraphicsTypes.pas
[FMX.][VCL.][LCL]TMSFNCHTMLEngine.pas
[FMX.][VCL.][LCL]TMSFNCStyles.pas
[FMX.][VCL.][LCL]TMSFNCTypes.pas
[FMX.][VCL.][LCL]TMSFNCURLBitmapContainer.pas
[FMX.][VCL.][LCL]TMSFNCUtils.pas

Note that with this set of units, you are able to write a custom component from scratch. A tutorial on writing a custom component can be found in this blog post: http://www.tmssoftware.com/site/blog.asp?post=346

Pieter Scheldeman


Bookmarks: 

This blog post has not received any comments yet.



Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
Comment:
 
Change Image
Fill in the characters from the image above:
 

All fields are required.
 




Previous  |  Next  |  Index