Over Danny

Delphi trainer en ontwikkelaar.

5 quick tips for removing ARC in Delphi Sydney

With the release of version 10.4 Sydney, Delphi has officially moved away from the ARC memory model in the mobile compilers. This was announced in 2018, there is some nice background info in this blog post by Marco Cantu.

So how do you do a quick check if your Delphi mobile code has ARC dependencies you should fix?

Tip #1 – Run on Windows with ReportMemoryLeaksOnShutDown := True

This instructs the FastMM memory manager to report memory leaks. Simply run your iOS or Android App on Windows (with the Windows Platform active), perform the usual actions an end-user would perform and close the application. Any memory leaks will be reported and should be fixed.

In your application source code add this line:

  ReportMemoryLeaksOnShutdown := True;
  Application.CreateForm(TFormMain, FormMain);

If you have a memory leak a message like this will popup after closing the application.

Unexpected Memory Leak

Tip #2 –  Search | Find In Files (Shift-Ctrl-F) for any “.Create” code

Most ARC (Automatic reference Counting) code should be changed to CTFF (Create Try Finally Free). Just check if there is a try-finally and a free directly after the .Create. Not all Create code needs a try-finally-free, as some instances are owned by their container, for instance in a TObjectList<T> that may take ownership of the instantiated object.

Change this ARC code

procedure DoSpellCheck;
  Harry: TWizard;
  Harry := TWizard.Create; 

To this CTFF code

procedure DoSpellCheck; 
  Harry: TWizard; 
  Harry := TWizard.Create;

Some code can not be easily changed from ARC to CTFF, mostly due to the Free needing to be called at some unspecified time in the future, which for instance is common in multi-threaded code. If this applies to you then you could take a look at smart pointers in Spring4D using Shared.Make(TObject.Create), or take a look at the new custom managed records which where introduced in Delphi 10.4. Both options enable you to use ARC style freeing of resources, within the now default unified memory model.

Tip #3 – Use a tool to check for memory leaks

The code in tip #1 uses the built-in FastMM4 and is free. There is also a dual-license newer version FastMM5, both are however limited to Windows. Luckily there is a nice and simple free library called leakcheck that does this for all Delphi platforms. Alternatively, if detecting leaks in Windows only is preferred, the commercial DeLeaker has a lot of options and easy overview of memory leaks. A nice summary of these tools and more can be found in the blog post of Wagner Landgraf.

Tip #4 – Check for platform specific code

The short check for memory leaks under the Windows platform will skip platform specific code for Android and iOS, so you should check for compiler directive based platform dependencies {$IFDEF ANDROID}, {$IFDEF IOS}, but also for run-time dependencies like with TOSVersion.TPlatform.pfiOS and TOSVersion.TPlatform.pfAndroid. Note that the compiler directive AUTOREFCOUNT has been removed in Delphi 10.4, but its entirely possible you used this in your own code to check for ARC availablity.

Tip 5 – Check for weak references

These are mostly introduced to enable multiple references to instances without affecting reference count in combination with ARC. Do not just remove them, they can also be used for other reference counted data structures which may not have anything to do with ARC perse.

Even without ARC, reference counting still exists in Delphi. The compiler will still automagically reference count interfaces and strings. The same mechanism is also used for the new custom managed records.

RAD Studio 10.4 Sydney Webinar 16 juni 2020

View of Sydney Harbour

Barnsten organiseert een RAD Studio 10.4 webinar op 16 juni om 14:00 waarbij ik de mogelijkheid krijg om enkele van de nieuwe features van Delphi 10.4 wat uitgebreider te laten zien. Nu ben ik best blij met de nieuwe versie dus die kans laat ik niet voorbij gaan.

Onderwerpen zijn  de werking en voordelen van per control VCL Styling, het hoe en wat van de nieuwe Delphi Language Server Protocol server voor Code Insight en de ins en outs van Managed Records en het uitfaseren van ARC (Automatic Reference Counting) op de mobile platforms. Er zit nog wel meer in qua onderwerpen, maar die kom je vanzelf tegen als je het webinar volgt.

Meer info en inschrijven kan met deze link::

Ontdek RAD Studio 10.4 Sydney – Webinar 16 juni – 14.00 uur

Tot volgende week dinsdag bij de Q&A !

Delphi 10.4 Sydney

Delphi 10.4 Sydney has all the right ingredients. From support for Android OpenJDK up to the soon to be required iOS Storyboard; it’s all there. The all new LSP adds syntactic sugar and the per control Windows VCL styling is the finishing touch.

For me the timely support for iOS storyboard is the winner, as Apple requires us to start using this on June 30th.

Support for Android OpenJDK is very cool, as this opens up the Android environment even more. Although you could already customize and modify just about anything in Delphi on Android (adding APIs and even CPU code), this makes it easier still.

And what about this LSP, the Language Server Protocol? We now have all kinds of syntax, code, class completion and what not in multiple LSP processes! This is also very open, allowing you to add your own. Most important for you as a developer, it’s asynchronous, so you’ll never lose keystrokes again, when code completion kicks in.

Starting from this release we now have the same classic unified memory model for all platforms. This means that you no longer have to write specific code for ARC (Automatic reference Counting) anymore, because its gone (except for strings and interfaces). If you’ve adhered to the CTFF (Create Try Finally Free) pattern on mobile platforms there is no need to change any code, if not, you may want to add a Free at some places in your source code.

Last, but not least, per control Windows VCL styling. It’s now possible to use multiple VCL styles in one application at the same time, even on the same form. This will allow you to mix and match your main VCL style with form specific styling to better match specific styling of certain third-party controls you can not VCL style themselves. Finishing touch indeed.

All features can be found right here: http://docwiki.embarcadero.com/RADStudio/Sydney/en/What%27s_New

You can download Delphi 10.4 Sydney from the new customer portal here: https://my.embarcadero.com/#downloadsPage The online web installer and the offline ISO installer are now compatible with one another. The ISO file contains the files the web installer would otherwise download, so you can choose the method you prefer.

iOS storyboard support in Delphi 10.4

No worries, the iOS storyboard that Apple requires for iOS Apps starting June 30th is covered in the soon to be released Delphi 10.4.

The way you add a iOS storyboard is, as always in Delphi, very easy to use. Just head over to Project Options | Icons and reconfigure your launch images. Also set the new Dark and Light background, and you’re done.

The other requirements added by Apple may or may not mean you have to add or change some of your code. Please use the news item from Apple to review any necessary changes at https://developer.apple.com/news/?id=03262020b.

It’s good to know that everything we need for our iOS development is there, and, well, I just had to share this tiny bit of information. Thanks to Jim McKeeth for allowing me to share this with you before Delphi 10.4 ships.

Delphi 10.4 Coming Soon

Delphi 10 Parallel Programming Training – 10 en 11 juni 2020 (verplaatst)

Altijd al willen weten hoe je al die CPU cores voor je kunt laten werken in Delphi?

In deze twee daagse training gaan we gebruik maken van de System.Threading bibliotheek in Delphi, ook wel de PPL, Parallel Programming Library genoemd.

We starten eenvoudig met TTask en TFuture en TParallel.For en breiden dan uit naar hoe je dit eenvoudig, robuust en zonder dead locks toepast in je database verbindingen, communicatie met webservices en andere taken die je asynchroon wilt uitvoeren.

Maak je applicatie meer responsive en gebruik die cores!

De training is ingepland voor 10 en 11 juni bij het jachthuis te Doorn (nabij Utrecht).
Dit event is verplaatst in verband met het corona virus en wordt later opnieuw ingepland.


SDN Event – 3 april 2020 (verplaatst)

Het SDN event van vrijdag 3 april komt er aan!

Op die dag gaan we aan de slag met Micro Services, hoe maak je die in Delphi, maar belangrijker nog, hoe deploy je die op IIS/Windows en op Apache/Linux. En ook, hoe zorg je voor automated certificate renewal voor je https met Let’s Encrypt?

Verder hebben we een, denken wij, leuk idee voor een shoot out sessie. Samen met Cary Jensen heb ik in Denemarken een dergelijke sessie gedaan, maar dan bijna een hele dag. Met de deelnemers samen behandelen we elk onderwerp dat jullie aandragen, met code snippets en jullie ideëén maken we er een interactieve sessie van. Waar moet je aan denken? Bijvoorbeeld code snippets met TStringBuilder, TFDMemtable local storage met Lockbox encryption, embedding assembler, fun met RTTI, of…. wat denken jullie?


Dit event is verplaatst in verband met het corona virus. Hopelijk zien we elkaar weer in juni!

Happy Delphi 25th birthday!


Happy Delphi 25th birthday!

Wow, its been 25 years already since I first met Delphi in its pre-release of version 1.0.

During the past 25 years Delphi created a world of opportunities for me. I’ve travelled the world for Delphi, creating software in Portugal, Delphi courses in France, presenting in Denmark and meeting up with developers in New Zealand. Most of my work was in the Netherlands, but even so its diversity of use in this tiny country always manages to amaze me. From high-performance statistics, stock market, multi-threaded geo analysis, insurance expert systems to project and hour registration systems. The largest user base for desktop software I worked on was 100.000+ users, but I know of Delphi software that has millions of users. All in all, you can literally find Delphi software everywhere, meaning you get to go everywhere and build all kinds of systems as a Delphi developer, which to me is just the greatest thing!

More stories here:

Happy Delphi 25th Birthday and #Delphi25th everyone!


Delphi 10 VCL Essentials training – 11-13 maart 2020

We beginnen het nieuwe jaar goed met nu al een driedaagse Delphi 10 VCL Essentials training in de planning, op woensdag 11 maart tot en met vriidag 13 maart in de mooie locatie van het Jachthuis Beukenrode in Doorn.

De training is bedoeld voor coders en developers met enige ervaring in programmeren in  Delphi of een andere programmeeromgeving die graag snel en goed Delphi willen leren of beter leren kennen. We beginnen met een overview van alles wat je met Delphi en de VCL kunt, maar gaan ook in op details als de event-loop en de interne werking van de VCL (visual component library) en RTL (run-time library). In de driedaagse training leer je je Windows applicaties maken met Delphi, gebruik maken van een database via FireDAC. Verder in-memory en local datasets, debugging, de RTL, Windows-10 styling en zelfs wat generics.

Inschrijven en details van de agenda vindt je hier:

CodeRage 2019 RAD Server Key Value sessions

Thank you for attending my CodeRage 2019 sessions on RAD Server.

The Key Value storage created, deployed and used in the sessions is very simple to build, but also very versatile in its use. Hopefully you will find as many, or even more, uses as I have for the Key Value server code in your own projects with RAD Server.

If you want to replay the sessions, please visit the CodeRage 2019 playlist on YouTube here.

Please find the download with Delphi sources and a partial emsserver.ini here:
Download source and emsserver.ini
The download has been compressed with RAR with password coderage2019
and has the following SHA-256 checksum

David Intersimone (DavidI) has created an excellent handbook on RAD Server which can be found here.

Have fun creating your own RAD Server solutions!

Some after session thoughts

In an attempt to shorten the RADServerKeyValue Client video a part of the video at the end was removed that should not have been removed. This involves using a key/value pair with uploading a larger or more complex text. The source code in the rar file you can download has the correct source code.

This Key Value store code has special handling for any key with a value ‘body’. In response to this keyword the RAD Server Key Value package assumes the body of the Request contains a UTF8 encoded text to be placed in the value for the dictionary. This makes it possible to put text in the Key Value storage that would be difficult to put as a URL parameter, either due to size constraints for URL segments, or due to special characters not allowed in URL parameters.

By setting the recycle time of the IIS ISAPI to 24 hours, the in-memory Key Value pairs will remain available for that period. If you want you can add persistency for this dictionary by storing the data in a database in the RAD Server backend.

You may want to add manual support for different MIME types with EndPointProduce and EndpointConsume and use EMSFileResource and EMSDBResource to feed files or database tables back to the client.


Delphi 10 Rio VCL Essentials training – 27-29 november 2019

De driedaagse Delphi 10 VCL Essentials training start 27 november 2019 op de mooie locatie van het Jachthuis Beukenrode in Doorn.

De training is bedoeld voor developers met enige ervaring in programmeren. Maar ook ervaren ontwikkelaars waarderen hem, niet alleen door de overview van alles wat je met Delphi en de VCL kunt, maar ook door de deep-dive in details als de event-loop en de interne werking van de VCL (visual component library) en RTL (run-time library). In de driedaagse training leer je je Windows applicaties maken met Delphi, gebruik maken van een database via FireDAC. Verder in-memory en local datasets, debugging, de RTL, Windows-10 styling en zelfs wat generics.

Inschrijven en details van de agenda vindt je hier: