0item(s)

You have no items in your shopping cart.

Product was successfully added to your shopping cart.
Swipe to the left

Igniting the passion for Delphi for future generations

By Margreet van Muyden February 13, 2019 50 Views No comments

Tuesday, February 12, 2019 - in TMS Software office


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.

view plain text

  1. procedure TTMSFNCMasterMindControl.HandleKeyDown(var Key: Word;
  2. Shift: TShiftState);
  3. var
  4. dataInt: NativeInt;
  5. begin
  6. case Key of
  7. KEY_LEFT: SelectedItemIndex := GetPreviousSelectableItem;
  8. KEY_RIGHT: SelectedItemIndex := GetNextSelectableItem;
  9. KEY_UP:
  10. begin
  11. if (SelectedItemIndex >= 0) and (Items.Items[SelectedItemIndex].DataString = 'image') then
  12. begin
  13. dataInt := 1 + Items[SelectedItemIndex].DataInteger;
  14. if (dataInt > 6)then
  15. dataInt := 1;
  16. Items[SelectedItemIndex].DataInteger := dataInt;
  17. Invalidate;
  18. end;
  19. end;
  20. ….
  21. end;

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

view plain text

  1. procedure TTMSFNCMasterMindControl.HandleMouseUp(Button: TTMSFNCMouseButton;
  2. Shift: TShiftState; X, Y: Single);
  3. var
  4. dataInt: NativeInt;
  5. begin
  6. if Enabled then
  7. begin
  8. inherited;
  9. if (SelectedItemIndex >= 0) and (Items.Items[SelectedItemIndex].DataString = 'image') then
  10. begin
  11. dataInt := 1 + Items[SelectedItemIndex].DataInteger;
  12. if (dataInt > 6)then
  13. dataInt := 1;
  14. Items[SelectedItemIndex].DataInteger := dataInt;
  15. Invalidate;
  16. end;
  17. 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:

view plain text

  1. procedure TTMSFNCMasterMindControl.DrawItemContent(AGraphics: TTMSFNCGraphics;
  2. ADisplayItem: TTMSFNCCustomSelectorDisplayItem);
  3. var
  4. di: TTMSFNCCustomSelectorItem;
  5. idx: Integer;
  6. bmp: TTMSFNCBitmap;
  7. pt1: TPointF;
  8. checkPinsRect: TRectF;
  9. side: Single;
  10. i: Integer;
  11. tempPCorrect: Integer;
  12. tempCCorrect: Integer;
  13. w, h: Single;
  14. s: string;
  15. begin
  16. inherited;
  17. di := ADisplayItem.Item;
  18. // draw the peg using a bitmapcontainer image
  19. if Assigned(di) and (di.DataString = 'image') then
  20. begin
  21. idx := di.DataInteger;
  22. AGraphics.BitmapContainer := BitmapContainer;
  23. case idx of
  24. 1: s := 'red';
  25. 2: s := 'blue';
  26. 3: s := 'yellow';
  27. 4: s := 'orange';
  28. 5: s := 'green';
  29. 6: s := 'purple';
  30. else s := 'empty';
  31. end;
  32. AGraphics.DrawBitmapWithName(ADisplayItem.Rect, s);
  33. end;
  34. // draw the score
  35. if Assigned(di) and (di.DataString = 'check') then
  36. begin
  37. w := ADisplayItem.Rect.Right - ADisplayItem.Rect.Left;
  38. h := ADisplayItem.Rect.Bottom - ADisplayItem.Rect.Top;
  39. if(w < h) then
  40. side := w / 2
  41. else
  42. side := h / 2;
  43. tempPCorrect := FPosCorrect;
  44. tempCCorrect := FColorCorrect;
  45. // retrieve scores
  46. for i := 0 to 3 do
  47. begin
  48. if(tempPCorrect > 0) then
  49. begin
  50. FTColors[i]:= gcRed;
  51. Dec(tempPCorrect);
  52. end
  53. else if (tempCCorrect > 0) then
  54. begin
  55. FTColors[i] := gcWhite;
  56. Dec(tempCCorrect);
  57. end
  58. else
  59. FTColors[i] := gcNull;
  60. end;
  61. // Mastermind row is active, so use active color
  62. if (Enabled = true) or (FPosCorrect = 4) then
  63. begin
  64. AGraphics.Fill.Color := activeColor;
  65. AGraphics.Stroke.Color := activeColor;
  66. end
  67. else
  68. begin
  69. AGraphics.Fill.Color := boardcolor;
  70. AGraphics.Stroke.Color := boardcolor;
  71. end;
  72. // draw 4 score circles in correct score color
  73. AGraphics.DrawRectangle(ADisplayItem.Rect);
  74. AGraphics.Stroke.Color := gcBlack;
  75. checkPinsRect := RectF(ADisplayItem.Rect.Left + 2, ADisplayItem.Rect.Top + 2, ADisplayItem.Rect.Left + side - 2, ADisplayItem.Rect.Top + side - 2);
  76. AGraphics.Fill.Color := FTColors[0];
  77. AGraphics.DrawEllipse(checkPinsRect);
  78. checkPinsRect := RectF(ADisplayItem.Rect.Left + 2, ADisplayItem.Rect.Top + side + 2, ADisplayItem.Rect.Left + side - 2, ADisplayItem.Rect.Top + (side * 2) - 2);
  79. AGraphics.Fill.Color := FTColors[1];
  80. AGraphics.DrawEllipse(checkPinsRect);
  81. checkPinsRect := RectF(ADisplayItem.Rect.Left + side + 2, ADisplayItem.Rect.Top + 2, ADisplayItem.Rect.Left + (side*2) - 2, ADisplayItem.Rect.Top + side - 2);
  82. AGraphics.Fill.Color := FTColors[2];
  83. AGraphics.DrawEllipse(checkPinsRect);
  84. checkPinsRect := RectF(ADisplayItem.Rect.Left + side + 2, ADisplayItem.Rect.Top + side + 2, ADisplayItem.Rect.Left + (side*2) - 2, ADisplayItem.Rect.Top + (side * 2) - 2);
  85. AGraphics.Fill.Color := FTColors[3];
  86. AGraphics.DrawEllipse(checkPinsRect);
  87. end;
  88. 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.

Blog by Gjalt Vanhauwaert

TMS Web Core v1.1 meetup at tmssoftware offices

By Margreet van Muyden December 20, 2018 139 Views No comments


Tuesday Dec 18 we organised again a free meetup for Delphi enthusiasts to learn & see the latest developments for TMS WEB Core here in our offices. We were pleased to see over 30 Delphi developers from Belgium and The Netherlands.

On the agenda, we had:

  • 14h00 – 14h30 : Anonymous methods, Matthias Gaertner
  • 14h30 – 15h00 : Bluetooth, Matthias Gaertner
  • 15h15 – 16h00 : TMS WEB Core use case, Filip Lagrou
  • 16h15 – 17h15 : TMS WEB Core Verona 1.1, Bruno Fierens
The pas2js compiler engineer Matthias Gaertner presented upcoming support for anonymous methods in the pas2js Pascal to JavaScript compiler. We look forward to integrate this new compiler feature in an upcoming TMS WEB Core version and this will definitely make writing code for consuming cloud services a lot cleaner.


The next topic presented by Matthias Gaertner was about the use of bluetooth device communication directly from the browser. Yes, it is amazing that the latest Chrome browser version (and also in development versions of FireFox) there is now the capability to connect & communicate with bluetooth LE devices. This is another big step forward towards making web applications more universal and enable these to control hardware. Matthias Gaertner showed how to write a web application that controlled a small relay board via bluetooth from our beloved Pascal code.

Next was Filip Lagrou, Embarcadero MVP and CEO from our consulting partner company C-Quel. Filip Lagrou showed us how this company uses both TMS FNC componentsto create Windows and Linux client applications using the same code and the same FNC UI controls. Filip Lagrou showed us how the TMS WEB Core technology is now being employed in the first web client projects being rolled out to his customers. The team from C-Quel also showed how RemObjects DataAbstract was used as a backend for a TMS WEB Core application.

The last session was given by Bruno Fierens and focused on the new TMS WEB Core v1.1 Verona features. First, the concept Progressive Web Application was explained. Bruno Fierens showed how this new project type makes it extremely easy to create a Progressive Web Application and attendees were able to experiment with the sample Progressive Web Application from their smartphone while the presentation was going on.
Next, the new accelerator key support and autocompletion edit control were demonstrated. This brings the convenience of keyboard shortcut controlled applications to web or progressive web applications.
Finally, the easiness of PayPal payment integration was demonstrated, first in a standalone small code sample and then as part of a new web shop sample project we created.
The slides from the presentation can be downloaded here

In between the sessions, we also received a big surprise. As the chief editor Detlef Overbeek from the Blaise Pascal magazine was present, he took the opportunity to hand-out the yearly magazine award for our TMS WEB Core / FNC developments. It's clear we were very honored with this award and this unplanned surprise during our meetup event.

After these content-heavy sessions, we took plenty of time to sit together and enjoy tapas and wine. It was great to mingle with Delphi enthusiasts, learn about the fantastic projects each of us are creating with Delphi and brainstorm about future exciting things to do with Delphi.

Do you want to experience a meetup like this again in 2019? Then make sure to leave a comment and share your thoughts with us! More pictures can be found on our Facebook page.

Happy holidays!



Directions for ARC Memory Management in Delphi

By Margreet van Muyden October 26, 2018 55 Views No comments

posted by marcocantu

Directions for ARC Memory Management in Delphi

With the coming 10.3 release, RAD Studio R&D and PM teams are making Delphi's new directions in memory management official.


A few years back, when Embarcadero started building new Delphi compilers for platforms other than Windows there was a lot of discussion how compatible the new Delphi should have been with the current language, in terms of core language features and overall perception of the language. Eventually the decision that emerged was to do keep an extremely large degree of compatibility, with a few significant and bold steps towards a language more capable of attracting a new generation of developers.

What is Automatic Reference Counting?

(cross linked objects with weak references)

One of the changes in this space was the decision to embrace a new memory management model for the mobile platforms, following what Apple was already pushing as the iOS memory model: Automatic Reference Counting or ARC. On a memory-constrained device like a mobile phone using garbage collection is often considered an issue (as you end up consuming much more memory than strictly needed, and that also affects battery life) and ARC offers a simplified memory management model, easier to use in simple scenarios, fully deterministic, and robust.

That’s why Delphi picked the same model, extending the object reference counting model what has already been available for interfaces for a long time, making it more powerful with weak and unsafe references, and expanding it to plain object variables. This model does offer some significant advantages, and one of the original ideas was to expand it to the Delphi language on all platforms.

ARC Drawbacks

(entangled weak and strong references)

A few years after that planned was rolled out, we still see its advantages and benefits, but we have a much more clear picture of the drawbacks of the ARC model and what its effect will be in making it the default also on Windows and VCL applications.

We have long considered ARC memory management to be an improvement over the traditional Delphi model, as it removes and simplifies some of the memory management. However, we have learned when building and maintaining our large libraries and by talking with customers on complex code bases, that while ARC looks great on paper and for local variables and simpler scenarios, it often causes a lot of trouble for complex scenarios. Also the TComponent ownership model all of our libraries are centered on is at odds with ARC, making it complex to ARC-enable existing component libraries.
We could have decided to go “full ARC” also on Windows, but that would have caused a significant breakage of existing applications and components, causing far more trouble than the Unicode migration we did in the past -- which was due to external pressure of offering good international support and the fact that the underlying operating systems (starting with Windows) were also Unicode.

We had many requests to make ARC optional, but an ARC-enabled object won’t easily coexist with a non-ARC-enabled one, and we would need containers for both flavors of objects and would make it impossible to mix them. This would end up as an extremely complex scenario. Mixing ARC and non-ARC is not a viable solution, but also keeping different memory models on different platforms end up defeating the entire idea of “single source, multi platform” which is a core tenet of today’s Delphi focus both server side (Windows and Linux) and client site on all platforms you can build FireMonkey applications for.

Another significant angle is that ARC has a runtime cost. While things can be optimized and improved, at the end automatic management is not totally free. While Garbage Collection has a (very high) cost when it kicks in, ARC has a cost on objects lifetime and object interaction (unless you cautiously use const for all parameters passing). A positive effect of disabling ARC is a measurable performance improvement. Finally, ARC in Delphi is a bit at odds with the C++ side of the product, which is an integral part of RAD Studio.

The New Plan: Phasing Out ARC

(using interfaces in Delphi)

With all of these considerations in mind, and after extensive internal discussions, also involving partners and external developers, we have reached the conclusion that the best way forward is to move off the ARC model as a default memory management solution, and compensate for its loss with other alternatives.

In practical terms, the Linux 64-bit compiler in the 10.3 Rio release is going to offer the traditional Delphi memory management of the Windows platforms, making your Windows and Linux server side code totally equivalent -- at least in terms of Delphi language and memory management.

The go-forward plan is to not embrace ARC for the coming macOS 64-bit platform (so all desktop platforms are and will remain on the non-ARC model) and to disable ARC also for mobile platforms in the future (most likely around the next major release after 10.3). Notice that in 10.3 Rio the mobile compilers remain with ARC enabled, exactly like in 10.2.

What else for Modern Memory Management?

(Source: https://pixabay.com/photo-1751201/)

We still think reference counted memory management is relevant, but rather than introducing a new mechanism for it, we prefer to leverage and augment the existing reference counted model that is used by interfaces and strings in Delphi. This has been the case for a long time. Interface references and object references to the same object can cause trouble if not handled properly, but this is something most Delphi developers already know how to handle and there is a lot of documentation on the subject.

Interface references have been recently extended with weak references and even unsafe references. These additional options largely increase the power and flexibility of “ARC for interfaces”. In other words, while we are going to remove ARC for object references, ARC for interface references is a feature of the language that has been and will remain available.

On top of this, we want to improve and simplify the management of the lifetime (and memory management) of local short-lived objects with stack references. This is a not feature we are going to introduce in 10.3, but something we are actively investigating and can be partially implemented by developers leveraging managed records (a new language feature in 10.3).

Wrapping Up

(Memory leaks tracking made simple)

While we understand that this change to the plans made a few years back can come as a surprise and affect existing code, developers who were unhappy about the ARC model, supporting multiple models on different platforms, and its loss of performance compared to native memory management, are likely going appreciate the decision.

Offering alternative ways to further simplify Delphi memory management is in RAD Studio’s roadmap, but the current set of features (interfaces with reference counting and support for weak and unsafe references, the component ownership model, and the standard common practices) already provide a good framework to reduce the worry of manual memory management for Delphi developers.

Ultimately there is no perfect solution for memory management in programming languages, as automatic ones have their drawbacks, and manual ones are (well) manual. Delphi has had a very good balance in the past, which continues today and will only improve in the future.