Tag: firemonkey

REST API Server with Delphi and XData 5: Read and Watch

TMS XData 5 has been released with lots of new features!

Photo by Glenn Carstens-Peters on Unsplash

In addition to the recent release of TMS Aurelius 5, a new major version of TMS XData has been also released.

TMS XData 5 is the fifth major version of our framework to build multitier applications, including REST API server, and interface-based API client. It makes it easy to build server-side services that reach a broad range of clients, including browsers and mobile devices.

Among several features, TMS XData provides:

  • Automatic serialization/deserialization of pure Delphi objects, primitive types, method parameters;
  • Authentication and Authorization;
  • Powerful routing mechanism: route endpoints to methods in your code;
  • Automatic, zero-code Swagger/SwaggerUI support;
  • Interface-based client allows type-safe client applications without additional code;
  • Smooth TMS Aurelius integration allows CRUD endpoints of database entities automatically.

The new features released with XData 5 were also antecipated in a previous blog post,

The what’s new section in the documentation provides you with a full list, but here we will list a few:

Attribute-based Authorization

Developers will be able to just add authorization attributes to methods (service operations) or entities (automatic CRUD endpoints) and everything will be applied accordingly. Fine-tuning the protection of your REST API will never be as simple.

  [Authorize]
  IDocumentService = interface(IInvokable)
    procedure Insert(Value: TDoc);

    [AuthorizeScopes('user, editor')]
    procedure Modify(Value: TDoc);

    [AuthorizeScopes('admin')]
    procedure Delete(DocId: string);

    [AuthorizeClaims('email')]
    procedure Approve(DocId: string);
  end;

In the example above, all methods (endpoints) require authentication, because the interface has an Authorize attribute that propagates to all methods. So, to invoke Insert, user must be authenticated. Still, to invoke Modify, the user must be authenticated and have either user or editor scope in its credentials. He must be admin to invoke Delete, and finally to approve a document, user must have an email in its claims.

It’s also worth noting that the same strategy applies to entities that generate automatic CRUD endpoints:

  [Entity, Automapping]
  [EntityAuthorize]
  [EntityAuthorizeScopes('editor', [TEntitySetPermission.Modify, TEntitySetPermission.Insert])]
  [EntityAuthorizeScopes('admin', [TEntitySetPermission.Delete])]
  TCustomer = class
  {...}
  public
    property Id: Integer read FId write FId;
    property Name: string read FName write FName;
  end;

To access customer endpoints, user must be authenticated. But he must have editor privileges to modify and insert (PUT and POST) and must be admin to invoke DELETE. Easy and straightforward.

Async/Await Support in Web Applications

TMS XData is smoothly integrated with TMS Web Core, the TMS framework to build web applications.

Now your can use async/await mechanism in TXDataWebClient methods that invoke XData server endpoints. As an example, invoking a XData REST API endpoint asynchronously will be as easy as doing this:

PendingOrders := await(XClient.List<TOrder>('$filter=Status eq pending'));
if PendingOrders.Count = 0 then
  Exit; // no pending orders to process

The single line above will build the HTTP request with proper URL endpoint and HTTP method, invoke it, deserialize the returned JSON into a list of TOrder objects, and all asynchronously! The await function will guarantee that the next line will be executed only after the async execution is executed. Can’t get easier than that.

Multitenant Servers

This is a feature released with TMS Aurelius, which now has the global filter mechanism, allowing you to build multitenant applications.

But XData now includes a few nice mechanisms to integrate with such Aurelius filters that makes building multitenant servers very easily!

From a single handler for the event OnManagerCreate, you can enable the “Multitenant” filter for all requests:

  Manager.EnableFilter('Multitenant')
    .SetParam('tenantId', 'acme');

After you’ve enabled the “Multitenant” filter passing the proper id, you can use the Aurelius object manager as usual. But any request you do, like in the example, asking a list of products, will add the tenant filter.

Requests will not only apply global filters for queries, but also will enforce the filter in INSERT, UPDATE and DELETE operations.

Also building multi-database multitenant server will also be easy with the new TMultiTenantConnectionPool:

  FMultiPool := TMultiTenantConnectionPool.Create(
    TXDataHttpHeaderTenantResolver.Create('tenant-id'),
    TDBConnectionPoolFactory.Create
    );

The pool will automatically choose the correct database based on the HTTP header tenant-id – or any other criteria you might choose. All transparently.

Come See it Live!

Want to know more about XData? Want to see the new features live?

The free webinar “Introducing XData 5” will be held next Wednesday, March 31st, at 4pm UTC at the TMS Web Academy.

In this webinar, Wagner Landgraf, TMS XData architect, will explain to newcomers what TMS XData is about, how to use it, and then show all the new features in action, with real code.

And of course, it will be a live session: you can ask questions and participate! Register now for the “Introducing XData 5” webinar and learn more about this amazing REST API framework!

Read More

Read More

Workflow visualization and organization in FMX

Intro

The multi-device, true native app platform The FireMonkey® framework is the app development and runtime platform behind RAD Studio, Delphi and C++Builder. FireMonkey is designed for teams building multi-device, true native apps for Windows, OS X, Android and iOS, and getting them to app stores and enterprises fast.

source: https://www.embarcadero.com/products/rad-studio/fm-application-platform

FMX (FireMonkey) released in 2011 and shortly after we delivered a first set of components. Today, we want to show you the TTMSFNCKanbanBoard component, a highly configurable workflow visualization and organization component.

Features

Below is a list of the most important features the TTMSFNCKanbanBoard has to offer. The features are not limited to this list, but this will give you a quick insight on what we offer to be able to create an application that visualizes a workflow environment in FireMonkey.

  • Multi collapsible column support
  • Filtering and Sorting
  • Item autosizing
  • HTML formatted text support
  • Collapsible items
  • Database adapter
  • Drag & Drop support
  • Editing support
  • Fully customizable column & item appearance & custom Kanban board item drawing
  • Optional header & footer per column

Learn More!

Want to learn more about what the TTMSFNCKanbanBoard can do? Here is a video that highlights some of the above features through a demo application.

Download & Explore!

The TTMSFNCKanbanBoard component is part of the TMS FNC UI Pack, which, on top of FMX, also offers the ability to write your code once and target other frameworks (VCL, LCL and WEB). You can download a full featured trial version of the TMS FNC UI Pack and start exploring the capabilities of the TTMSFNCKanbanBoard component.

Coming up

The TTMSFNCKanbanBoard is the fourth of a series of components that is covered to empower your FMX (FireMonkey) developments. We started the series with a general overview of the most important components that we have to offer, followed by the TTMSFNCRichEditorTTMSFNCPlanner and the TTMSFNCTreeView. Next up will be the TTMSFNCGrid, a feature rich and powerful grid component.

Read More

Read More

Workflow visualization and organization in FMX

Intro

The multi-device, true native app platform The FireMonkey® framework is the app development and runtime platform behind RAD Studio, Delphi and C++Builder. FireMonkey is designed for teams building multi-device, true native apps for Windows, OS X, Android and iOS, and getting them to app stores and enterprises fast.

source: https://www.embarcadero.com/products/rad-studio/fm-application-platform

FMX (FireMonkey) released in 2011 and shortly after we delivered a first set of components. Today, we want to show you the TTMSFNCKanbanBoard component, a highly configurable workflow visualization and organization component.

Features

Below is a list of the most important features the TTMSFNCKanbanBoard has to offer. The features are not limited to this list, but this will give you a quick insight on what we offer to be able to create an application that visualizes a workflow environment in FireMonkey.

  • Multi collapsible column support
  • Filtering and Sorting
  • Item autosizing
  • HTML formatted text support
  • Collapsible items
  • Database adapter
  • Drag & Drop support
  • Editing support
  • Fully customizable column & item appearance & custom Kanban board item drawing
  • Optional header & footer per column

Learn More!

Want to learn more about what the TTMSFNCKanbanBoard can do? Here is a video that highlights some of the above features through a demo application.

Download & Explore!

The TTMSFNCKanbanBoard component is part of the TMS FNC UI Pack, which, on top of FMX, also offers the ability to write your code once and target other frameworks (VCL, LCL and WEB). You can download a full featured trial version of the TMS FNC UI Pack and start exploring the capabilities of the TTMSFNCKanbanBoard component.

Coming up

The TTMSFNCKanbanBoard is the fourth of a series of components that is covered to empower your FMX (FireMonkey) developments. We started the series with a general overview of the most important components that we have to offer, followed by the TTMSFNCRichEditorTTMSFNCPlanner and the TTMSFNCTreeView. Next up will be the TTMSFNCGrid, a feature rich and powerful grid component.

Read More

Read More

REST API Server with Delphi and XData 5: Read and Watch

TMS XData 5 has been released with lots of new features!

Photo by Glenn Carstens-Peters on Unsplash

In addition to the recent release of TMS Aurelius 5, a new major version of TMS XData has been also released.

TMS XData 5 is the fifth major version of our framework to build multitier applications, including REST API server, and interface-based API client. It makes it easy to build server-side services that reach a broad range of clients, including browsers and mobile devices.

Among several features, TMS XData provides:

  • Automatic serialization/deserialization of pure Delphi objects, primitive types, method parameters;
  • Authentication and Authorization;
  • Powerful routing mechanism: route endpoints to methods in your code;
  • Automatic, zero-code Swagger/SwaggerUI support;
  • Interface-based client allows type-safe client applications without additional code;
  • Smooth TMS Aurelius integration allows CRUD endpoints of database entities automatically.

The new features released with XData 5 were also antecipated in a previous blog post,

The what’s new section in the documentation provides you with a full list, but here we will list a few:

Attribute-based Authorization

Developers will be able to just add authorization attributes to methods (service operations) or entities (automatic CRUD endpoints) and everything will be applied accordingly. Fine-tuning the protection of your REST API will never be as simple.

  [Authorize]
  IDocumentService = interface(IInvokable)
    procedure Insert(Value: TDoc);

    [AuthorizeScopes('user, editor')]
    procedure Modify(Value: TDoc);

    [AuthorizeScopes('admin')]
    procedure Delete(DocId: string);

    [AuthorizeClaims('email')]
    procedure Approve(DocId: string);
  end;

In the example above, all methods (endpoints) require authentication, because the interface has an Authorize attribute that propagates to all methods. So, to invoke Insert, user must be authenticated. Still, to invoke Modify, the user must be authenticated and have either user or editor scope in its credentials. He must be admin to invoke Delete, and finally to approve a document, user must have an email in its claims.

It’s also worth noting that the same strategy applies to entities that generate automatic CRUD endpoints:

  [Entity, Automapping]
  [EntityAuthorize]
  [EntityAuthorizeScopes('editor', [TEntitySetPermission.Modify, TEntitySetPermission.Insert])]
  [EntityAuthorizeScopes('admin', [TEntitySetPermission.Delete])]
  TCustomer = class
  {...}
  public
    property Id: Integer read FId write FId;
    property Name: string read FName write FName;
  end;

To access customer endpoints, user must be authenticated. But he must have editor privileges to modify and insert (PUT and POST) and must be admin to invoke DELETE. Easy and straightforward.

Async/Await Support in Web Applications

TMS XData is smoothly integrated with TMS Web Core, the TMS framework to build web applications.

Now your can use async/await mechanism in TXDataWebClient methods that invoke XData server endpoints. As an example, invoking a XData REST API endpoint asynchronously will be as easy as doing this:

PendingOrders := await(XClient.List<TOrder>('$filter=Status eq pending'));
if PendingOrders.Count = 0 then
  Exit; // no pending orders to process

The single line above will build the HTTP request with proper URL endpoint and HTTP method, invoke it, deserialize the returned JSON into a list of TOrder objects, and all asynchronously! The await function will guarantee that the next line will be executed only after the async execution is executed. Can’t get easier than that.

Multitenant Servers

This is a feature released with TMS Aurelius, which now has the global filter mechanism, allowing you to build multitenant applications.

But XData now includes a few nice mechanisms to integrate with such Aurelius filters that makes building multitenant servers very easily!

From a single handler for the event OnManagerCreate, you can enable the “Multitenant” filter for all requests:

  Manager.EnableFilter('Multitenant')
    .SetParam('tenantId', 'acme');

After you’ve enabled the “Multitenant” filter passing the proper id, you can use the Aurelius object manager as usual. But any request you do, like in the example, asking a list of products, will add the tenant filter.

Requests will not only apply global filters for queries, but also will enforce the filter in INSERT, UPDATE and DELETE operations.

Also building multi-database multitenant server will also be easy with the new TMultiTenantConnectionPool:

  FMultiPool := TMultiTenantConnectionPool.Create(
    TXDataHttpHeaderTenantResolver.Create('tenant-id'),
    TDBConnectionPoolFactory.Create
    );

The pool will automatically choose the correct database based on the HTTP header tenant-id – or any other criteria you might choose. All transparently.

Come See it Live!

Want to know more about XData? Want to see the new features live?

The free webinar “Introducing XData 5” will be held next Wednesday, March 31st, at 4pm UTC at the TMS Web Academy.

In this webinar, Wagner Landgraf, TMS XData architect, will explain to newcomers what TMS XData is about, how to use it, and then show all the new features in action, with real code.

And of course, it will be a live session: you can ask questions and participate! Register now for the “Introducing XData 5” webinar and learn more about this amazing REST API framework!

Read More

Read More

Delphi 10.4 FMX UnsatisfiedLinkError

I am trying to build my app for Android 64 bit with Delphi 10.4. I have been building for Android 32 bit successfully so far. However Google Play requires 64 bit release. Here is the error I am getting. JNI DETECTED ERROR IN APPLICATION: JNI NewObjectV called with pending exception java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.embarcadero.BiKolay-Cnwx1cniUgstNJrRAjvrEQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.embarcadero.BiKolay-Cnwx1cniUgstNJrRAjvrEQ==/lib/arm64, /data/app/com.embarcadero.BiKolay-Cnwx1cniUgstNJrRAjvrEQ==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libopencv_java3.so" P.s. Blank 64-bit app that doesn't have any libs in it works just fine. But I don't need that. How can I deploy my app to my phone as an 64 bit app with Delphi FMX?
Read More

How to record microphone to MP3 with Delphi 10.4.2 on FMX Windows?

In FMX Delphi 10.4.2 I'm recording audio with this code: var fMicrophone: TAudioCaptureDevice; begin fMicrophone := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice; if fMicrophone = nil then begin ShowMessage('Audio capturing device not available'); Exit; end; MicFilterStringLabel.Text := fMicrophone.FilterString; // filter is *.wav RecordButton.Enabled := False; StopButton.Enabled := True; // Sets the name of the file to save the recorded data fMicrophone.FileName := TPath.Combine(gPreferences.TemporaryFolder, 'samplefile.mp3'); fMicrophone.StartCapture; end; // later the stop button calls fMicrophone.StopCapture; This does not seem to create an authentic MP3 file. Perhaps it's still making a WAV file but just with the MP3 extension. Can this component make an MP3 file? Failing that, is there a component that will make MP3 files? (The mitov components don't seem to install on Delphi 10.4.2 and I don't have an email answer back from him about that yet.)
Read More

How to enable an AniIndicator1 in a TThread , not in the main process in FMX?

Hi I have a multidevice APP based on FMX. The synch database process takes longer time, I need a AniIndicator1 enabled to tell user to wait. Following code tested in n android phone, sometime works, sometime only finish the first synch DB function, sometimes finish first 3 and then exited. Sometimes none of the sychDB function was taken place. procedure TForm1.BtnSyncDBClick(Sender: TObject); begin Application.ProcessMessages; memo3.Lines.Add('Start synchronising...'); AniIndicator1.Visible:=true; AniIndicator1.Enabled:=true; TThread.CreateAnonymousThread( procedure begin try SynchDB_A; memo3.Lines.Add('finish 0'); SynchDB_B; memo3.Lines.Add('finish 1'); SynchDB_C ; memo3.Lines.Add('finish 2'); SynchDB_D; memo3.Lines.Add('finish 3'); finally AniIndicator1.Enabled := False; AniIndicator1.Visible := False; end; end ).start; end; So, I am wondering if I can put the AniIndicator1.enable function in a child thread and use the main thread to synchDB? Tried following code , not working as expected. procedure TForm1.BtnSyncDBClick(Sender: TObject); begin TThread.CreateAnonymousThread( procedure begin try TThread.Synchronize (TThread.CurrentThread, procedure () begin Memo1.lines.Add('Start... '); AniIndicator1.Visible := True; AniIndicator1.Enabled := True; end); finally end; end ).Start; try SynchDB_A; memo3.Lines.Add('finish 0'); SynchDB_B; memo3.Lines.Add('finish 1'); SynchDB_C ; memo3.Lines.Add('finish 2'); SynchDB_D; memo3.Lines.Add('finish 3'); finally AniIndicator1.Enabled := False; AniIndicator1.Visible := False; end; end; Any expert could help with this , either fix the first code to guarantee always work, child thread not being killed, or start SynchDB in the main process and enable AniIndicator1 in a child thread and make it spinning. Or any other easy way to tell user to wait while the synchDB working? thanks in advance.
Read More

Create Numeric Keyboard Firemonkey Delphi and Dynamic create button with Font are not working

I’m doing a touch system (Windows) that needs numeric keyboard to insert user, manual entry, password, exit system. I prefered to create Button, but the attribute Font are not working.
I created a class:
unit uKeyboard;

interface

uses
… … Read More

Read More

Your familiar HotSpot Image comes to the TMS FNC UI Pack v3.3

We have a new major release of the TMS FNC UI Pack, next to some fixes and new features, we have added the TTTMSFNCHotSpotImage to the already extensive set of powerful and feature-rich UI controls that can be used cross framework and cross platform with just one code base.

TMS FNC Controls can be simultaneously used on these frameworks:

  • VCL
  • WEB
  • FMX
  • LCL

TMS FNC Controls can be simultaneously used on these operating systems/browsers:

  •           

TMS FNC Controls can be simultaneously used on these IDE’s:

  •    

 

TTMSFNCHotSpotImage

This component is already known to VCL and FMX users and for the TMS WEB Core users who don’t know the component, you can compare it with the idea of an Image Map.

The TTMSFNCHotSpotImage (further referred to as ‘hotspotimage’) gives you the ability to choose one image and then add different areas (hotspots) with which you can interact and each of them can have their own appearance.

TTMSFNCHotSpotImageEditor

Our team considers the convenience of visually creating and configuring your components, that is why an editor was created to help you design your hotspots. This can be done in designtime by a double click or right-click on the hotspotimage. To give you full control over your hotspotimage, the editor is also available in runtime.

Hotspotimage Demo

To let you get more familiar with the component, we have created a demo application that you can find here.

This topic describes the steps we have taken to create such a demo application. It is a simple example of a selection game that shows a lot of features.
You’ll need to find the correct country for a given capital.

The TTMSFNCHotSpotImageEditor (further referred to as ‘hotspotimage editor’) can be used to create the hotspots of the different countries. All of the following can be done in the code as well. But to give an example of the possibilities, we will explain how to this visually.

The image can be added in the editor or with the Bitmap property.

On the top of the editor there is a toolbar that can be used to create or manipulate the poylgons.

Because there is a high contrast and the edgy shape of the different countries, the Magic Wand was the perfect tool to create the polygons.

In the panel on the right, you have the buttons ‘Hover’, ‘Selected’ and ‘Down’. With these buttons you can change the appearance for the different states.
If none of the hotspots are selected in the listbox, then you are able to change the default appearance used on newly created hotspots in the different pages.
On the other hand, if you select a hotspot, you can change the appearance for the specific hotspot.
This way, I’ve changed the Fill kind of the polygon to a texture with an image of the flag. You can also change the stroke and font used by the hotspot.

To change the name of the different hotspots, select the hotspot in the listbox, edit the text in the edit box and click on the ‘Change Name’ button.

Now let’s have a look at the code that is used. Besides the code used to change the settings between game mode and normal selection mode, only two specific events are needed.

The event OnSelectedHotSpotChange where the check is added to see if the selection is allowed.
As it would not be helpful to unselect a hotspot while playing the game.

procedure TForm2.TMSFNCHotSpotImage1SelectedHotSpotChange(Sender: TObject; AIndex: Integer; var Allow: Boolean);
begin
  if (AIndex >= 0) and not TMSFNCHotSpotImage1.HotSpots[AIndex].Selected then
    Allow := True
  else
    Allow := False;
end;

If it is allowed, then we can catch the change of the index with the event OnSelectedHotSpotChanged.

In this event we check if the name of the selected hotspot is the same as the one we were looking for.
if that is the case we add a point to our score and pick a new random country. If not, then the selected index is set back to false and if the answer was wrong for the second time, then we retrieve the hotspot by its name and and fill that one with a red color.

procedure TForm2.TMSFNCHotSpotImage1SelectedHotSpotChanged(Sender: TObject; AIndex: Integer);
var
  hsIdx: Integer;
begin
  if (length(countries) > 0) and Start then
  begin
    if TMSFNCHotSpotImage1.HotSpots[AIndex].Name = countries[idx] then
    begin
      Label2.Text := cities[idx] + ' is the capital of ' + countries[idx] + ' ('+ Point.ToString+')';
      Score := Score + Point;
      Label3.Text := Score.ToString + '/10';

      Delete(cities, idx, 1);
      Delete(countries, idx, 1);
      NextCapital;
    end
    else
    begin
      TMSFNCHotSpotImage1.HotSpots[AIndex].Selected := False;
      Point := Point - 0.5;

      if Point = 0 then
      begin
        hsIdx := TMSFNCHotSpotImage1.GetHotSpotIndexByName(countries[idx]);
        if hsIdx > -1 then
        begin
          TMSFNCHotSpotImage1.HotSpots[hsIdx].Appearance.SelectedFill.Color := gcTomato;
          TMSFNCHotSpotImage1.HotSpots[hsIdx].Selected := True;
        end;

        Label2.Text := cities[idx] + ' is not the capital of ' + TMSFNCHotSpotImage1.HotSpots[AIndex].Name + ' but ' + countries[idx] + ' (Next question)';

        Delete(cities, idx, 1);
        Delete(countries, idx, 1);

        NextCapital;
      end
      else
        Label2.Text := cities[idx] + ' is not the capital of ' + TMSFNCHotSpotImage1.HotSpots[AIndex].Name + ' ('+Point.ToString+')';
    end;
  end;
end;

The rest of the code can be found in the demo folder of the TMS FNC UI Pack.

This video of Gjalt’s 101 gives you a quick example on how the ‘Hover Bitmap’ property is used:


Read More

Read More