Category: Firemonkey

How to detect when reopen an app sleeping in background on iOS (Firemonkey)?

I want to use TouchID to protect an application. The TouchID function,(implemented in Activate event) work corect if i start (a closed) application. But nothing happened when i reactivate same application from background (is already opened in background). Any ideea on how to detect which event i have to use to capture reactivation of an open application on iOS (firemonkey) ? Any help will be apreciated !
Read More

How do I get a second descendant of TTreeViewItem to show on the TreeView

Using Delphi 10.3 and Fmx, how do I get the second descendant of TTreeviewItem to show its text ? The first descendant works fine. The second one (T3) always shows blank. In this sample the "Parent" and "Text" are assigned correctly to the Item. But in my project the parent will not get assigned, but the text will. unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, FMX.TreeView; type TForm1 = class(TForm) vue: TTreeView; procedure FormCreate(Sender: TObject); private public end; var Form1: TForm1; type T1 = class (TTreeViewItem) constructor Create (AOwner : TTreeViewItem); reintroduce; virtual; end; T2 = class (TTreeViewItem) constructor Create (AOwner : TTreeViewItem); reintroduce; virtual; end; T3 = class (T1) constructor Create (AOwner : TTreeViewItem); override; end; implementation {$R *.fmx} { T1 } constructor T1.Create(AOwner: TTreeViewItem); begin inherited Create (AOwner); Parent := AOwner; Text := 'T1'; end; { T2 } constructor T2.Create(AOwner: TTreeViewItem); begin inherited Create (Aowner); Parent := AOwner; Text := 'T2'; end; { T3 } constructor T3.Create(AOwner: TTreeViewItem); begin inherited; // Parent := AOwner; Text := 'T3'; end; procedure TForm1.FormCreate(Sender: TObject); var R, I1, I2 : TTreeViewItem; T1a : T1; T2a : T2; T3a : T3; begin R := TTreeViewItem.Create (vue); R.Parent := vue; R.Text := 'Root'; { Doesnt Work } I1 := TTreeViewItem.Create (R); I1.Parent := R; I1.Text := 'First'; { Works } I2 := TTreeViewItem.Create (R); I2.Parent := R; I2.Text := 'Second'; { This works } T1a := T1.Create (I1); { This works } T2a := T2.Create (I1); { This doesnt work } T3a := T3.Create (I1); end; end. Here's the dfm object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 480 ClientWidth = 640 FormFactor.Width = 320 FormFactor.Height = 480 FormFactor.Devices = [Desktop] OnCreate = FormCreate DesignerMasterStyle = 0 object vue: TTreeView Align = Left Size.Width = 217.000000000000000000 Size.Height = 480.000000000000000000 Size.PlatformDefault = False TabOrder = 0 Viewport.Width = 213.000000000000000000 Viewport.Height = 476.000000000000000000 end end
Read More

Delphi XE7 FMX Android FTP Connection Exception

how can i catch a connection exception on android when connection to FTP. Code At the Moment : idftp1.Host := Servidor_ftp; idftp1.Username:= Usuario_ftp; idftp1.Password:= Contraseña_ftp; Try idftp1.Port := StrToInt(Puerto_ftp); except idftp1.Port := 21; End; Try idftp1.Connect; idftp1.Passive := true; if Carpeta_ftp = '' then IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), Nombre_pistola+'.txt' , False ) else IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), Carpeta_ftp+Nombre_pistola+'.txt', False ); idftp1.Disconnect; except ShowMessage('Hay un error con la conexion al FTP, compruebe si tiene internet y si esta bien configurado todo.'); End; The connection works correctly when all is configured correctly (server, user, pass, port) but it could be configured incorrectly and in that case it would not connect, if i use that code with windows i get an exception after the timeout, but on android it just stays there and i get the message "Wait for app or kill app" Thank you.
Read More

How to set alignment in Fire Monkey multi device application at runtime C++ Builder?

The main problem is FMX dose not support the SomeController->Align = alClient; but that code will work in the VLC application, so after many googling I fine TAlignLayout.Client for my case and the documentation of it is here and here, I try many way to use it but it wont work! I want create Frame in the runtime as you can see in the following code: TSettings *appSettingsFrame; appSettingsFrame = new TSettings(viewSettings); appSettingsFrame->Parent = viewSettings; appSettingsFrame->Align = TAlignLayout.Client; TSettings is Fire Monkey Frame and I use the above code in FormCreate event to create it, at runtime. viewSettings is TMultiView and it's place for appSettingsFrame. If I run application for Android target, the error massage point me to 'TAlinLayout' dose not refer to a value. And if I run application for 32-bit Windows target, the error massage point me to Improper use of typedef 'TAlignLayout'.
Read More

Happy Birthday Delphi!

Time flies as today we already celebrate the 24th birthday of Delphi. The past 24 years have been an amazing, adventurous and always exciting voyage!

Looking back at 1995, Delphi was nothing short of a dramatic breakthrough in productivity for software development.

Before, I still remember that creating a Windows application created with Turbo Pascal for Windows also required having the Resource Workshop tool ready. We’d typically create dialogs and other resources via the Resource Workshop. And then came the tedious process of linking the UI control logic to the elements on the dialog via IDs. One mismatching ID and the dialog would be broken. Other than this, we merely had to use the Windows API to achieve even the smallest UI feature.

Then came Delphi. No more need for Resource Workshop. Direct usage of the Windows API could be dramatically decreased as Delphi introduced the integrated form designer and more importantly the UI control model mapping on existing Windows controls but also open to extend and create custom controls, seamless binding to a database and even live design-time data. In a nutshell, us, Pascal developers could create Windows applications 10 times faster with 10 times more features.

The next 24 years continued that quest for packing ever more programming productivity and reaching out to new targets. Soon Win32 support was added in Delphi 2. The world of web development opened with the inclusion of the breakthrough product IntraWeb from Atozed. Ever more out of the box support for all kinds of databases, multi-tier development and internet server development found a place in successive Delphi releases. It was waiting till 2009 for the breakthrough to add Unicode support and 2011 to bring the power of Delphi to the 4 major operating systems: Windows, macOS, iOS and Android. We conveniently skip the short passages of bringing Delphi to Linux with Kylix and to the .NET framework world with Delphi 8

In a fast moving and ever changing technology landscape, one could wonder why someone can have this passionate relationship with Delphi?

For a change, let’s try to find an analogy with real estate instead of with cars 🙂 The three most important things when looking for real estate are: “Location, Location, Location”.

So, the three most important things for a Delphi developer are:

  • Component model: abstracting technology and allowing to focus on business problems instead of technology
  • Component model: allowing code reuse among developers in the team, across applications and across platforms
  • Component model: providing an access to 3rd party code libraries in a consistent way

There are of course many more virtues to the Delphi language, IDE and ecosystem and things to be passionate about. Backwards compatibility is one such example and a natural, expressive non-cryptic language is another one. Very fast compile times to facilitate quick debug cycles. The list goes on. Let us know your most loved Delphi features!

In these 24 years, TMS software evolved along with Delphi also quite a bit. Where in 1995, it was just “me, myself and I” encapsulating code in components initialy mainly for reuse in my own consulting projects, TMS has grown into a unique and fantastic team I am truly proud of!

Nothing is more fun than brainstorming with like-minded enthusiast experts about how we could make the Delphi developers even more product or reach into new territories. With every new introduced technology in Delphi, we jumped on the wagon and created components for it. Yes, back in the days, we even had our grid working in Kylix and also for Delphi for .NET . More succesful projects were the creation of a suite of UI controls for IntraWeb, the first FireMonkey components on the market for cross platform development, the leading Delphi ORM Aurelius, the REST server technology via XData, … the list is endless. Last year we introduced a new framework for developing in a really RAD way from the Delphi IDE rich & modern web client applications using our beloved language with TMS WEB Core. This goes hand in hand with our FNC UI control developments enabling to use one set of UI controls not only in VCL, FMX, LCL applications but also for TMS WEB Core web applications. And for the backend of the web applications, this integrates nicely and smoothly with our TMS XData REST server technology.

But it is not all new technology all the time. We continue to take great care, enhance, extend, improve and polish very widely used flagship products like TMS Component Pack, our set of over 400 VCL UI components that saw its life back in 1998. Especially for the birthday of Delphi today, we released an update 9.0.4.0 with all latest improvements. Of course, active registered users get this update free, for users with an expired subscription we have discounts to renew and for new users we have this week a 20% discount! See our other blog post for details!

Have a great Delphi Birthday today!

Read More

Read More

Igniting the passion for Delphi for future generations


A local school in the town where the TMS office is located organized last week for the kids a project where they could experience an entire day in a working place they dream of for their future career.
We had the pleasure to welcome Obama in our office. Obama is an 11-year-old boy who would love to become a software developer. We at TMS Software offered him the opportunity to follow us for a day and see what it takes to be a software developer. To inspire Obama and raise the interest of the next generation, we wanted to show Obama what a great variety of platforms we could tackle with our beloved tool Delphi and our frameworks. And what better way to captivate the youth then to create a game?

We choose the code-breaking game Mastermind that was invented in 1970 by Mordecai Meirowitz.
For those who don’t know the game, the purpose is to guess the code created by your opponent, or in this case the computer, by using four colored pegs. There are six colors to choose from and after each guess the opponent gives feedback on how many colors are correct and how many colored pegs are in the right position. In our game we decided that the red mark would indicate that the peg was in the correct place and a white mark if the color was used in the code, but not on the position you’ve guessed. To make it a little easier, we’ve also made sure that the colors are only used once and no empty spots are in the pattern.

If you already want to play our game before we explain how everything works, you can do this at www.tmssoftware.com/MasterMind.

As we wanted to show the power of our components and use it on almost every platform on the planet, it was a logical choice to work with our FNC components. This way we can use the same codebase to create a VCL, FMX and web application. A progressive web application to be precise. The advantages for a PWA application are clear:
– The application has a responsive design, this means that it adapts automatically to the device screen so it looks good on mobile and desktop.
– It is aware of status, it continues to work also when you are offline.
– You can install the application on mobile devices and Chrome OS, without going to a censored application store.
– It looks like a native application running full-screen with access to the hardware.
The only remark here is that it should initially be accessed via HTTPS. As you can see on both pictures below an example where you can see the web application on the left and then the downloaded app on the right which is launched as installed app and is running full-screen and offline.


So, a TMS web progressive web application is the best way to let Obama show what he built to all of his friends and family. It is as easy as sharing the link to play the game in an internet browser and you can also download and install it on your phone or tablet to have it available even when you are offline or want to save some mobile data.

To put the icing on the cake, we didn’t just create the game as progressive web application. This served also as a proof of concept to create a TMS Electron project created in Delphi from the same source code! This technology is in development in our lab and this will be part of the TMS WEB Core 1.2 Padua release. It allowed us to have an out-of-the-box working and installable desktop application for Windows, macOS (macOS 64-bit app to be precise), and on Linux in a matter of minutes. Here are some screenshots of this cross platform TMS Electron desktop application on Windows, macOS and Ubuntu. As we guess that many of you are eager to work with this awesome technology, we are working hard to make a TMS WEB Core 1.2 Padua Beta release available as soon as possible to our TMS ALL-ACCESS users.








Now to get to the programming. We started with the idea to create a control for one entry containing the four colored pins, a check button and the four markers that evaluate your guess.

A quick look in the wide range of FNC UI components we’ve already available, learned us that the TTMSFNCBitmapSelector looks the most similar component to what we want to create. So we took the custom FNC component this TTMSFNCBitmapSelector was derived from and started with the TTMSFNCDefaultSelector. This would be the basis for our FNC UI component TTMSFNCMasterMindControl. We built the board by creating 12 of our UI controls and placed them underneath each other with the use of top align.

It took us no effort to evenly space everything horizontally or to scale everything when the window is resized, as this is already done in the class TTMSFNCDefaultSelector. We just had to draw our images and the first line was already visible on our screen.


To get a little more in detail. We’ve created one row with five columns, where we use images to draw the four pegs with one TTMSFNCBitmapContainer, which contains the images for all the colors. The public property DataInteger that exists for every TTMSFNCCustomSelectorItem in the TTMSFNCDefaultSelector is used to hold the value of the selected color. The “Check” is just text shown in the item and the four check markers are drawn via TTMSFNCGraphics, where we just calculate the optimal size to draw four circles and fill the color of the ellipsis according to the number of correct pegs.
Then we checked how the interaction with mouse, keyboard and touch could be realized to ensure the game can be played on a variety of devices. With mouse or touch, consecutive clicks on each of the 4 positions cycles through the colors. We’ve added navigation between positions with the left and right arrow keys and cycling through color per position with arrow up and down. This UI behavior was again fairly easy to implement due to the fact that most of the behavior was already in the superclass.
We use the left and right arrow keys to navigate within our own control and as you can see below, you have the prove that this is very simple as the GetPreviousSelectableItem and GetNextSelectableItem are both functions from the TTMSFNCCustomSelector.

procedure TTMSFNCMasterMindControl.HandleKeyDown(var Key: Word;
  Shift: TShiftState);
var
  dataInt: NativeInt;
begin
  case Key of
    KEY_LEFT: SelectedItemIndex := GetPreviousSelectableItem;
    KEY_RIGHT: SelectedItemIndex := GetNextSelectableItem;
    KEY_UP:
      begin
        if (SelectedItemIndex >= 0) and (Items.Items[SelectedItemIndex].DataString = 'image') then
        begin
          dataInt := 1 + Items[SelectedItemIndex].DataInteger;
          if (dataInt > 6)then
            dataInt := 1;
          Items[SelectedItemIndex].DataInteger := dataInt;
          Invalidate;
        end;
      end;
      ….

end;

The code to change the peg color from the mouse up handler override is:

procedure TTMSFNCMasterMindControl.HandleMouseUp(Button: TTMSFNCMouseButton;
  Shift: TShiftState; X, Y: Single);
var
  dataInt: NativeInt;
begin
  if Enabled then
  begin
    inherited;
    if (SelectedItemIndex >= 0) and (Items.Items[SelectedItemIndex].DataString = 'image') then
    begin
      dataInt := 1 + Items[SelectedItemIndex].DataInteger;
      if (dataInt > 6)then
        dataInt := 1;
      Items[SelectedItemIndex].DataInteger := dataInt;
      Invalidate;
  end;
end;

We use the up and down keys to change the public DataInteger property of the selected item of type TTMSFNCCustomSelectorItem which changes the bitmap image of the selected peg in our DrawItemContent function.
The code is:

procedure TTMSFNCMasterMindControl.DrawItemContent(AGraphics: TTMSFNCGraphics;
  ADisplayItem: TTMSFNCCustomSelectorDisplayItem);
var
  di: TTMSFNCCustomSelectorItem;
  idx: Integer;
  bmp: TTMSFNCBitmap;
  pt1: TPointF;
  checkPinsRect: TRectF;
  side: Single;
  i: Integer;
  tempPCorrect: Integer;
  tempCCorrect: Integer;
  w, h: Single;
  s: string;
begin
  inherited;
  di := ADisplayItem.Item;
  // draw the peg using a bitmapcontainer image
  if Assigned(di) and (di.DataString = 'image') then
  begin
    idx := di.DataInteger;
    AGraphics.BitmapContainer := BitmapContainer;
      case idx of
        1: s := 'red';
        2: s := 'blue';
        3: s := 'yellow';
        4: s := 'orange';
        5: s := 'green';
        6: s := 'purple';
        else s := 'empty';
      end;
    AGraphics.DrawBitmapWithName(ADisplayItem.Rect, s);
  end;
  // draw the score
  if Assigned(di) and (di.DataString = 'check') then
  begin
    w := ADisplayItem.Rect.Right - ADisplayItem.Rect.Left;
    h := ADisplayItem.Rect.Bottom - ADisplayItem.Rect.Top;
     if(w  0) then
       begin
         FTColors[i]:= gcRed;
         Dec(tempPCorrect);
       end
       else if (tempCCorrect > 0) then
       begin
         FTColors[i] := gcWhite;
         Dec(tempCCorrect);
       end
       else
         FTColors[i] := gcNull;
     end;
     // Mastermind row is active, so use active color
     if (Enabled = true) or (FPosCorrect = 4) then
     begin
       AGraphics.Fill.Color := activeColor;
       AGraphics.Stroke.Color := activeColor;
     end
     else
     begin
       AGraphics.Fill.Color := boardcolor;
       AGraphics.Stroke.Color := boardcolor;
     end;
     // draw 4 score circles in correct score color
     AGraphics.DrawRectangle(ADisplayItem.Rect);
     AGraphics.Stroke.Color := gcBlack;
     checkPinsRect := RectF(ADisplayItem.Rect.Left + 2, ADisplayItem.Rect.Top + 2, ADisplayItem.Rect.Left + side - 2, ADisplayItem.Rect.Top + side - 2);
     AGraphics.Fill.Color := FTColors[0];
     AGraphics.DrawEllipse(checkPinsRect);
     checkPinsRect := RectF(ADisplayItem.Rect.Left + 2, ADisplayItem.Rect.Top + side + 2, ADisplayItem.Rect.Left + side - 2, ADisplayItem.Rect.Top + (side * 2) - 2);
     AGraphics.Fill.Color := FTColors[1];
     AGraphics.DrawEllipse(checkPinsRect);
     checkPinsRect := RectF(ADisplayItem.Rect.Left + side + 2, ADisplayItem.Rect.Top + 2,  ADisplayItem.Rect.Left + (side*2) - 2, ADisplayItem.Rect.Top + side - 2);
     AGraphics.Fill.Color := FTColors[2];
     AGraphics.DrawEllipse(checkPinsRect);
     checkPinsRect := RectF(ADisplayItem.Rect.Left + side + 2, ADisplayItem.Rect.Top + side + 2, ADisplayItem.Rect.Left + (side*2) - 2, ADisplayItem.Rect.Top + (side * 2) - 2);
     AGraphics.Fill.Color := FTColors[3];
     AGraphics.DrawEllipse(checkPinsRect);
  end;
end;

As a last part we just had to implement some code to check the pattern and return an event if we did a guess. We then disable the FNC UI control for the active row on the board and enable the next row so we can move to the next step.
And that’s all for the component used in the game. Now we just have to create the form of the progressive web and Electron application and everyone can play the game anywhere, anytime.
Just to show the power and the time we gained by using one of our custom FNC components, we’ve also created a VCL and FireMonkey application with the same code.

To conclude, Obama was very proud of the game he helped creating and named ‘oBama mind’ and he showed it to all of his classmates. We hope that this way, he could transmit the passion for software development to his classmates and inspire a future generation of Delphi developers. To
illustrate the scope of this type of development with TMS WEB Core, Obama even showed it to his friends on his PlayStation 4, where you can play it on the built-in web browser. He said that now he is even more certain he wants to become a software developer!

We are one step closer to a future where Pascal programming is guaranteed.

The full source code for the Mastermind game that you can compile as VCL, FMX or Web core application is available for download.
As soon as TMS WEB Core v1.2 Padua will be released, you will also be able to compile it as an Electron Windows, macOS or Linux desktop application.

Read More

Read More

Is there an efficient way to load png-Images into a TImage object in FMX while it’s running?

In order to show many different sized PNG-Images (with transparent background) i Need to load them out of the resources of the program. In VCL, this is easy as you are able to simply use the TPngImage to load and assign them. In Firemonkey this doesn’t exist, so I need another way to do this. Is there a function in FMX in order to do that? Thanks
Read More