Marco Cantu

Syndicate content
Techie Italian Blogging on Delphi and More
Updated: 1 hour 37 min ago

Resuming the DelphiRazor Library Project

8 hours 53 sec ago

Given I've updated the library for 10.1 Berlin for a personal project, and also added a few new features, I decided to make my Delphi Razor HTML scripting library public again.

DelphiRazor is a limited close on ASP.NET Razor notation by Microsoft. In short, you can use spacial tags in your HTML files invoking server side processing for them, and get placeholders replaced by actual data from the server application (or a database, of course). With some logic, you can repeat HTML blocks (for each record in a dataset) of use conditional elements. In practice, there is a PageProducer type of component to hook individual pages to a WebBroker application, or you can sue the Engine component and automatically process an entire directory (or more complex folder structure).

The interesting element of this approach is you can easily embed this DelphiRazor tags into any modern HTML app. I recently worked on a Boostrap + JQuery site and adding dynamic database data to it ended up being as simple as using traditional web scripting languages. See this page I created for my wife activity with dynamic image filters and other nice JS tricks, with the data provided by DelphiRazor: http://www.beja.it/bags2016.html

The core library, a demo, some preliminary unit tests are now on:

https://github.com/marcocantu/DelphiRazor/

I'm also cleaning up and updating the rather detailed documentation, and plan moving it to the GitHub project wiki format for easier collaboration (I've started it here: https://github.com/marcocantu/DelphiRazor/wiki). More than willing to get help (but notice that I licensed this also to Embarcadero, so contributions can possibly also end up in the product -- it is already in use internally).

Near terms plans are to finish doc migration and write tests along side, next re-enable some of the features like sessions and permissions with a general architecture, third re-connect it to DataSnap -- as in the original version -- but also to EMS / RAD Server. Could be also hook into other third party libraries, of course.

Categories: News, Blogs, and Tips

Updating RAD Studio GetIt Package Manager Content for Berlin

Thu, 09/29/2016 - 03:04

We have recently gone back to updating and cleaning the content of GetIt packages, updating them to the last version and creating package versions for Berlin as needed. Plus we updated third party tools.

While the work isn't finished, I felt it is worth underlying the significant progress we have made. Now we have a person focus on GetIt content and we are really expecting to be timely in updating third party packages for new releases of RAD Studio and when there are updates in the actual libraries.

Of course we are also more than willing to extend the content of GetIt, and have also streamlined the rules to accept more contributions. We welcome open source libraries, trial or light versions of third party tools and libraries, add-on tools, and anything that can you might be interested to share with RAD Studio developers. Drop me an email to my marco.cantu@company address or Gmail, if you are interested.

The list of packages that have been updated includes the complete set of 14 TurboPack libraries, NexusDB Embedded, the trial versions of FirePower and InfoPower, and ICS. The last few pending packages are being updated this week. We also updated all IoT components for 10.1 Update 1 and added two additional IoT devices to the list.

 

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #46

Tue, 09/27/2016 - 00:57

It has been long time since I wrote a summary blog post, so this is just a collection of highlights. I'll try to get back to a decent frequency.

Official Embarcadero News

As you probably know we released RAD Studio Berlin Update 1. Check this blog post if you missed it.

Embarcadero is making our tools available to schools and universities. For free. Read the press release "Embarcadero Academic Program Offers Free Software Development Tools to Students" at http://www.businesswire.com/news/home/20160825005680/en/Embarcadero-Academic-Program-Offers-Free-Software-Development 

The company is also pushing on Windows 10 Anniversary Update support (with more features to come) but has announced that the Starter edition is remaining free. This is less powerful than the free edition for students, so it is more geared towards hobbyist and casual users, or anyone who wants to get started. Read the specific press release "Embarcadero Announces Support for Windows 10 Anniversary Update and Launches FREE Starter Edition" at http://www.businesswire.com/news/home/20160919006025/en

Update 1 and Operating Systems

My own tweet "My Nexus 5X running Android N with a notification from a Delphi app running on it" at https://twitter.com/marcocantu/status/775621077309489153

"Build apps for macOS Sierra and iOS 10 with RAD Studio Berlin Update 1" by Sarina at http://community.embarcadero.com/blogs/entry/build-apps-for-macos-sierra-and-ios-10-with-berlin-update-1

Technical Blog Posts

New "Migration and Update Center" on the Embarcadero web site, for anyone with projects on old versions of Delphi and C++Builder, available at https://www.embarcadero.com/rad-in-action/migration-upgrade-center

"18 Code Samples Highlighting New Features In RAD Studio Berlin" by Eli at http://community.embarcadero.com/blogs/entry/18-code-samples-highlighting-new-features-in-rad-studio-berlin. And also by the same author and Delphi MVP, "Three Ways To Easily Embed A Database With Your Android And IOS Apps" at http://community.embarcadero.com/blogs/entry/three-ways-to-easily-embed-a-database-with-your-android-and-ios-apps

Holger got back to blogging about Delphi, see https://flixengineering.com/blog. Great move! There are several very nice and technical blogs posts...

Interesting post by Warren, focused on cleaning your code from past bad habits, "Delphi Features I Avoid Using And Believe Need to be Gradually Eliminated from Codebases" at http://delphicodemonkey.blogspot.it/2016/09/delphi-features-i-avoid-using-and.html

Rather old but worth highlighting, is Jim's Top Ten Reasons to be a Delphi Developer at http://delphi.org/2016/07/top-10-reasons-to-be-a-delphi-developer/

Roman on EncodeString at http://blog.kassebaum.eu/?p=476

Jordi on using REST to talk with a Raspberry Pi at http://thundaxsoftware.blogspot.it/2016/09/delphi-rest-client-that-talks-to-rest.html

Documentation and Books

Petar shares the Word document of his detailed and very well researched book on Delphi's Parallel programming Library at https://onedrive.live.com/view.aspx?resid=400D26E601B2ABA2!143753&ithint=file%2cdocx. Kudos for the initiative. Already 50 pages of technical content, and open to contributions.

Did I mention Delphi Succinctly free ebook already? It was written by another Italian and another Marco: https://www.syncfusion.com/resources/techportal/details/ebooks/delphi. Good job.

Third Party Tools

Not really a Third Party tool, as it comes from Idera, but if you are using PowerShell you might be interested in this editor: https://www.idera.com/productssolutions/freetools/powershellplus/powershellregistrationform

​A great review of a great product, Nexus Quality Suite at http://delphicodemonkey.blogspot.it/2016/08/nexus-quality-suite-why-profiling-and.html

Roman updated IMAPSize (a very popular IMAP tool) to the latest Delphi, read more at http://blog.kassebaum.eu/?p=488

And Finally

Read the latest "Flotsam and Jetsam" post by Nick at http://www.codingindelphi.com/blog/flotsam-and-jetsam-116/. Nick is joining Embarcadero and I'm sure it will be a pleasure to work with him.

Categories: News, Blogs, and Tips

Using Migration Tool to Move Your Settings to Update 1

Mon, 09/26/2016 - 02:03

As you can read in the comments of the blog post announcing Berlin 10.1 Update 1, if you are using the GetIt based installer, the registry settings are not preserved as you uninstall, unlike when you are using the traditional ISO-based installer.

Beside manually backing up and restoring part of your registry configuration, a solution you can use is to leverage the  Migration Tool application that comes with RAD Studio to move your settings from RAD Studio 10.1 Berlin to Update 1. All it does is, in fact, backup and restore part of your registry! 

Update: Caveat And Manual Export

It looks like using the Migration Tools does not preserve components installation, although it seems it did for a few users. The safest way to retain your entire configuration seems to manualy export the registry section for RAD Studio and reimport it (overwriting the configuration generate after reinstalling). We fully understand this is not a good way to apply an update and are already at work for fixing this in the future.

Here is a short visual guide to the process.

1. Before you install Update 1, find and run the Migration Tool app, that is linked in the Windows Start menu, in the Embarcadero RAD Studio 10.1 group. This is where I see it in Windows 10:

2. As you run the Migration Tool, pick the option for exporting your settings:

3. Now choose the product version you want to backup. It should list different versions of RAD Studio you have on the machine. For 10.1 Berlin you have to pick the entry with "XE10", as this was wrongly listed in the original version of the tool.

4. Choose an file as a target, it will be an XML file but better go with the default extension. In the next screen keep all options selected (for the various areas of the configuration) and proceed.

5. Now install Update 1, which will trigger an uninstall. After the installation is over, run the product once (as this creates the proper default registry settings).

6. Now close the RAD Studio IDE, run the Migration Tools again, and this time pick the option to import the settings. Select the same file you saved earlier:

7. Now select the version these settings are for. After installation of Update 1, the Migration Tools will correctly list "10.1 Berlin" as the version so you shoudl pick that:

8. Select again all options (unless there is anything you want to retain from the new configuration), run the tool, and it should re-apply all of your settings.

9. Run the IDE again, and you should see custom configurations, additional packages, and everything else you had in the product -- and that is registry-based.

I hope this helps reducing the burden of installing this update, and again fully recommend making a copy of the registry entries before you start installing, either manually or even better with this tool. 

PS. As for why an update requires an re-installing, it would be the good topic for another blog post. In short a list of patched files will be huge (see as an example how we shipped 1 GB for a hot fix of 20 issues at http://cc.embarcadero.com/item/30476). Also making sure you get the right bits depending on your version, and that any file you modified won't be overridden, and considering if you installed a given hot fix already or not -- which changes the original size of the file to replace -- would make a fix extremely complex to handle and very likely to leave with a not working system.

As a reminder, for those suggesting you can do it better with your software, the Studio/18.0 folder alone under Program Files includes over 50,000 files for a full Enterprise install. And that doesn't include demos, platform libraries, and many other files that are installed in other locations. Just saying...

Categories: News, Blogs, and Tips

RAD Studio Berlin 10.1 Update 1 Available

Mon, 09/26/2016 - 01:59

Today, Embarcadero has released the first update of RAD Studio, Delphi, and C++Builder 10.1 Berlin, with many quality enhancements and some new features.

The new features include a version of the FireMonkey Grid control for iOS ,based on the native platform control, several other FMX enhancements, and support for iOS 10 (in particular the simulator) and improved compatibility for the coming macOS Sierra.

In terms of fixes, the C++ compiler has several improvements (almost 20), but also the Delphi one has a few issues (about 5) rounded up. All areas of the product have fixes and improvements, including an annoying DataSnap/REST issue, FireDAC, VCL, RTL, the IDE, the installer.... with over 100 public reported bugs fixes, and over 300 total (including internally reported issues).

Full description of the fixes to publicly reported bugs can be found at http://edn.embarcadero.com/article/44715

More information is also in the docWiki at http://docwiki.embarcadero.com/RADStudio/Berlin/en/Subscription_Update_1

If you are a registered user of 10.1 Berlin, you can download:

- the new GetIt based installer at http://cc.embarcadero.com/item/30613

- the ISO with the traditional installer at http://cc.embarcadero.com/item/30615

Before installing Update 1 you need to uninstall the RTM version of Berlin, even if the GetIt based installer doesn't prompt you to do so. You should be able to retain your configuration and installed third-party packages.

Update: As reported, GetIt based uninstall/install does nto preserve registry settings. Read about a workaround here: blog.marcocantu.com/blog/2016-september-migrationtool_update1.html

If you don't have a license to 10.1 Berlin, we have some great offers: mobile is free with Professional and there is an overall 10% "Update 1" special discount, plus you receive the free bonus pack with Konopka Controls, Radiant Shapes, and the PDF of my Object Pascal Handbook updated for 10.1 Berlin. More information on the offers, valid until September 30th, at https://www.embarcadero.com/radoffer

Categories: News, Blogs, and Tips

My 2016 Delphi BootCamp Language Session

Thu, 09/08/2016 - 01:23

On Tuesday, I gave my webinar at the Delphi BootCamp, focused on the ObjectPascal language. The focus was not exclusively on new and advanced features, but more of a complete overview of the language from the basics, focusing on differences form other mainstream programming languages.

You can find my slides at DelphiBootCamp2016Marco.pdf

All of the demos I used (most of which come form my Object Pascal Handbook) are available on a specific GitHub repository at https://github.com/marcocantu/2016DelphiLanguageBootCamp

The video replay is available on YouTube at https://www.youtube.com/watch?v=CqlHeBPKu-0

More information also on the webinar page at http://community.embarcadero.com/blogs/entry/delphi-boot-camp-day-2

PS: Today marks the 11th consecutive year of this blog, as you can see in the Archive (http://blog.marcocantu.com/archives.html), for a total of 1356 blog posts, including this one.

Categories: News, Blogs, and Tips

Windows Anniversary Update Article and Webinar

Fri, 09/02/2016 - 03:16

I published an article on this topic in the Embarcadero community and there is a Webinar scheduled for later this month.

The article is titled "Windows 10 Anniversary Update and RAD Studio" and you can read it at http://community.embarcadero.com/article/news/16424-windows-10-anniversary-update-and-rad-studio. It givens an overall picture of Delphi support for the latest version of Windows and links to a previous blog post I wrote here about Centennial support.

On September 22nd and 23rd I'll give a webinar on the combined topics, overall Windows 10 support and working with Centennial. More information and sign up at http://embt.co/delphiwin10webinar.

More is coming in this area in RAD Studio itself, but there is already all you need in the product to support the Anniversary Update at best.

PS. Don't forget to spread the word about the Delphi Boot Camp next week and the free Starter edition. We are seeing tremendous signups and adoption, but there is always room for spreading Delphi even more during the time of this special offer.

Categories: News, Blogs, and Tips

Linux Just Turned 25 and Delphi is Coming to Celebrate

Mon, 08/29/2016 - 01:27

The Linux operating system just turned 25 years old on August 25th. What a better occasion to show a couple of images of the coming Linux support for Delphi? The project code name is Godzilla. 

Here is a snapshot of the coming "Godzilla" IDE with the Linux target platform selected (and a specific distribution configured):

If you run PAServer on the Linux machine, as I did in the virtual machine on the right of the image below, just clicking the Run button or pressing F9 will compile and run the application on the target Linux machine, like it happens for mobile (well, no, actually quite a bit faster):

That's all for this preview. If you haven't already done so, upgrade to Delphi 10.1 Berlin now, with update subscription, to be among the first to try the Linux compiler when the beta version will be made available.

PS: As you can see from the demo code and the output, the Linux compiler is a 64-bit compiler.

Categories: News, Blogs, and Tips

A Free Delphi with Free Training

Fri, 08/26/2016 - 07:04

On the week from September 5 to 9th, Embarcadero is organizing a Delphi training course, 2 hours each day, with lessons given by some of the product experts (myself included, I'll cover the Delphi programming language). This is not meant for existing developers, but for new developers approaching the language -- or people who haven't used it in a while. Bootcamp information at at http://embt.co/2016delphicamp

So the invite is not mostly for the readers of this blog, but all of their friends interested in programming, so that they can see what Delphi is and start playing with it for free. In fact, as part of the deal there is a unique and time limited offer to order a copy of Delphi Starter (limited to Windows 32 bit and with a license for non business users, but fairly powerful) with a 100% discount, as you can see at https://www.embarcadero.com/products/delphi/starter/promotional-download. Again, this offer will be available only for 2 weeks, so tell your friends now.

Last but not least, as a registered user of the free Delphi Starter you'll be able to download the PDF of my Object Pascal Handbook, covering the Delphi language in details.

So in other words anyone interested in programming and in Delphi can get software, training, and a book -- all that's needed to get started with the product. That's a pretty amazing offer, and something that has not been done in the past. Delphi is an incredibly powerful tool, mostly hidden from view. This is a big chance to get it spread out a bit more.

Categories: News, Blogs, and Tips

The August 2016 Delphi (and RAD Studio) Roadmap

Thu, 08/04/2016 - 09:30

Embarcadero has published yesterday a new roadmap for Delphi, C++Builder, and RAD Studio, with the current plans for the next 18 months.

The document is available at:

http://community.embarcadero.com/article/news/16418-product-roadmap-august-2016

As you can see each of the PM (myself included) has added some detailed information. Over the next few weeks, I'll blog some more specific information about the features of the coming releases, and you'll start see some previews of future technologies as well.

PS. If I don't approve your comments here timely it is because I'm taking 10 days off, with limited connectivity. No bad intentions. ;-)

Categories: News, Blogs, and Tips

RAD Studio, Windows 10 Anniversary Update and Centennial

Wed, 08/03/2016 - 10:52

Windows 10 Anniversary Update shipped yesterday. This is the first mayor update to Windows 10, which shipped roughly one year ago. This new edition has many new features, mostly customer facing like the new support for Cortana. There is also, however, a new SDK that ships with it.

RAD Studio offers extensive support for Windows 10, offering new VCL controls that offer the Windows 10 UX, support for calling the new WinRT APIs, and integration of features based on those APIs into components (like the notification and the contracts components). The IDE also offers support for Windows 10 specific styles for both VCL and FireMonkey.

Among the many new features there is one of particular interest to Delphi and C++Builder developers: the Windows Desktop Bridge, also known as Project Centennial. This is a way to "convert" existing WinAPI applications into first-class UWP (Universal Windows Platform) applications, that can be executed "safely" on Windows 10 and distributed on the Windows 10 store (although this is still not enabled, as far as I can tell). These applications are natively compiled or .NET ones, and can still use older APIs and frameworks (WinAPI, MFC, VCL, WinForms, Silverlight, etc).

Creating a Centennial APPX

There are two ways to create the APPX files for the Centennial bridge. One is to use a converter from Microsoft, which will compare a vanilla image of the OS with that obtained after running the application installer, and capturing a differences among the two. This becomes the set of files to be packaged.

The second approach is to do the conversion process manually, as described on https://msdn.microsoft.com/windows/uwp/porting/desktop-to-uwp-manual-conversion. This is what I've done to convert a pretty simple Delphi applications into an APPX. First you need to call the makeappx utility, passing to a file with the list of files to embed (the executable, the graphical assets, and XML configuration file. and more) and as second parameter the output file:

makeappx.exe" pack /f mapfile /p myrssclient.appx

The other steps involve creating a certificate and using it to sign the APPX file with your credentials. So the real input to the process is the AppManifest.XML file and the list of files. The manifest has developer and application information, the logo, and a few more configuration settings. The list of files can be as simple as mine was:

[Files] "RssClient.exe" "RssClient.exe" "logo44x44.png" "logo44x44.png" "logo150x150.png" "logo150x150.png" "appxmanifest.xml" "AppxManifest.xml"

At this point I got my APPX file, I copied it into an Anniversary edition VM, and I was able to install it by opening the APPX as shown below:

If you follow the steps, the APPX get expanded into its own application folder and it is treated like a WinRT application, more than a traditional WinAPI ones. This is the installation folder structure (with the virtual file system under it):

The application is also added a a tile (with its logo) and can be started from there.

Next step is wait for Microsoft to enable distribution via the Windows 10 Store, that should allow most Delphi and C++Builder applications to be distributed and sold to large numbers of users, like it happens on the mobile platforms. Stay tuned.

PS. I'll cover more details in a coming "Windows 10 Anniversary Edition" Embarcadero webinar, later this month and we are planning to add specific support to simplify APPX deployment to the IDE in Berlin 10.1 Update 2, along with other new Windows 10 related features.

Categories: News, Blogs, and Tips

RAD Server Intro Video

Wed, 07/20/2016 - 07:36

Embarcadero has published on YouTube a nice video introducing RAD Server.

If the embedded version below doesn't work, go to:

https://youtu.be/HY0JRJPvjsU

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #45

Wed, 07/13/2016 - 07:12

It has been a couple of very busy weeks, so here is a general update, and more tech blogs to come.

Embarcadero News and Plans

In case you missed them, there have been a few updates with the company plans for RAD Studio going forward. In particular, I recommend reading:

I'll follow up ASAP with the status and plans for the Object Pascal language (or Delphi language, call it as you like) and some information about the VCL features and the new IDE designers under development mentioned by Brandon.

Technical Blog Posts Books
  • Daniele updated Delphi Cookbook is available. See http://www.danieleteti.it/delphi-cookbook-2nd-edition/
  • I've just finished updating my Object Pascal handbook for Delphi 10.1 Berlin. Not a large update, but there are a dozen new pages covering recent features and some updates and correction. I don't plan getting it in print -- not such a significant update. Will become available as an eBook only.

That's all for now. I really need to put more effort into blogging... stay tuned.

 

Categories: News, Blogs, and Tips

GetIt Packages Project Dependencies

Tue, 06/21/2016 - 01:50

A new feature of RAD Studio 10.1 Berlin that has gone mostly unnoticed is the ability to have project dependencies to GetIt packages. This makes is much easier to share projects that depend on third party libraries.

Since its introduction last year, the GetIt Package Manager has been continuously updated and extended with more capabilities. Since the beginning, the GetIt architecture allowed for dependencies: if library A depends on library B, when installing A you'll be prompted to install the dependent library B first. Now in Delphi and C++Builder 10.1 Berlin the mechanism has been extended so that a specific project can declare which libraries it depends on (this is not an automatic mechanism). Before looking to the solution, let me recap the issue at stake. Suppose that another developer send you a Delphi project, in my scenario one that uses the VirtualTreeView component. You open it, and if you don't have the package installed, you'll end up with an error like:

Now suppose that before sending me the project, the developer has opened the new GetIt Dependencies tab of the Project Options and set the proper dependencies, as below:

 

Now as I receive the project and open it, if I don't have the package installed, I'll be prompted to download it:

In theory, this will automatically trigger the download of the package. In practice, this triggers an error and and up making the dependencies unstable. So my recommendation is to select No, let the project open, eventually click Cancel if you receive an error that a component is not found, close all forms (but not the project), open the Project Options and install all missing packages, as below:

Now open your project forms, compile your projects and you should be up and running.

As you can see from reading above, there are still some hiccups in the process, but this is a very important new feature for the GetIt package manager, and I felt it was worth sharing despite the pending issues. If you go for a partially manual process, using the GetIt Dependencies page of the Project Options, everything should work fine.

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #44

Mon, 06/20/2016 - 08:04

Another round of blog posts covering news and blogs related with Delphi and RAD Studio.

Official Embarcadero News

A new PM has joined the RAD Studio PM team, with a specific focus on C++Builder. Great to have David Millington on board. You can read http://community.embarcadero.com/blogs/entry/hello-from-the-new-c-product-manager and https://parnassus.co/joining-embarcadero-c-product-manager/.

Speaking of another David, don't miss http://community.embarcadero.com/blogs/entry/calculating-how-i-am-and-how-many-years-i-have-been-married-using-delphi-and-c-builder

Finally, the GetIt Package Manager is going to have an increasingly important role, as you can read at http://community.embarcadero.com/blogs/entry/partner-collaboration-using-getit

​Technical Blog Posts

Variable Item Height with TListView in 10.1 Berlin by Sarina at http://community.embarcadero.com/blogs?view=entry&id=8574

The new "build with" and powered by" logos, at http://community.embarcadero.com/article/articles-support/171-rad-studio/16411-get-the-new-powered-by-built-with-and-built-for-logos

More from Uwe on his Package Magician at http://www.uweraabe.de/Blog/2016/06/19/package-magician-and-search-paths/

Jim is covering all of the cool apps submissions we received at http://community.embarcadero.com/blogs?view=blogger&layout=listings&id=390

Pawel on proximity apps at http://community.embarcadero.com/blogs?view=entry&id=8584

Projects and Libraries

FireBase is becoming critical for Android developers, great that Daniele Spinetti has a Delphi library to interface it at https://github.com/spinettaro/Firebase4Delphi

​Speaking of mobile, a FireMonkey sprite engine is available at https://github.com/dimsa/ShadowEngine

​And Events

In case you haven't seen it, Cary and Nick are teaming for Delphi Developer Days 2016: http://caryjensen.blogspot.it/2016/06/delphi-developer-days-2016-with-nick.html

That's all for this round...

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #44

Mon, 06/20/2016 - 07:53

Another round of blog posts covering news and blogs related with Delphi and RAD Studio.

Official Embarcadero News

A new PM has joined the RAD Studio PM team, with a specific focus on C++Builder. Great to have David Millington on board. You can read http://community.embarcadero.com/blogs/entry/hello-from-the-new-c-product-manager and https://parnassus.co/joining-embarcadero-c-product-manager/.

Speaking of another David, don't miss http://community.embarcadero.com/blogs/entry/calculating-how-i-am-and-how-many-years-i-have-been-married-using-delphi-and-c-builder

Finally, the GetIt Package Manager is going to have an increasingly important role, as you can read at http://community.embarcadero.com/blogs/entry/partner-collaboration-using-getit

​Technical Blog Posts

Variable Item Height with TListView in 10.1 Berlin by Sarina at http://community.embarcadero.com/blogs?view=entry&id=8574

The new "build with" and powered by" logos, at http://community.embarcadero.com/article/articles-support/171-rad-studio/16411-get-the-new-powered-by-built-with-and-built-for-logos

More from Uwe on his Package Magician at http://www.uweraabe.de/Blog/2016/06/19/package-magician-and-search-paths/

Jim is covering all of the cool apps submissions we received at http://community.embarcadero.com/blogs?view=blogger&layout=listings&id=390

Pawel on proximity apps at http://community.embarcadero.com/blogs?view=entry&id=8584

Projects and Libraries

FireBase is becoming critical for Android developers, great that Daniele Spinetti has a Delphi library to interface it at https://github.com/spinettaro/Firebase4Delphi

​Speaking of mobile, a FireMonkey sprite engine is available at https://github.com/dimsa/ShadowEngine

​And Events

In case you haven't seen it, Cary and Nick are teaming for Delphi Developer Days 2016: http://caryjensen.blogspot.it/2016/06/delphi-developer-days-2016-with-nick.html

That's all for this round...

Categories: News, Blogs, and Tips

Weak and Unsafe Interface References in Delphi 10.1 Berlin

Thu, 06/16/2016 - 07:32

Delphi 10.1 Berlin adds a couple of features to the Delphi language, bridging gaps between platforms and extending the Win32/Win64 interface reference model. This is not the only change to the language, but clearly the most relevant one. Another, focused on mobile, is the introduction of the native UTF8String type on all platforms, mobile compilers included.

But let me get back to the way references to interfaces work on the desktop compilers. By default, all references to interfaces use reference counting. As you assign a variable to the interface the reference count is increased, as the variable is set to nil or goes out of scope, the reference count is decreased. When the reference count gets to zero the object is deleted from memory. That is not actually always true, as the actual behavior is implemented by each class, so you can write a class that implements an interface and ignores the reference counting mechanism.

Anyway, getting back to the common scenarios in which reference count is active, you can have code like the following, which relies on reference counting to dispose the temporary object:

procedure TForm3.Button2Click(Sender: TObject); var one: ISimpleInterface; begin one := TObjectOne.Create; one.DoSomething; end;

What if the object has a standard reference count implementation and you want to create an interface reference that is kept out of the total count of references? You can now achieve this by adding the [unsafe] attribute to the interface variable declaration, changing the code above to:

procedure TForm3.Button2Click(Sender: TObject); var [unsafe] one: ISimpleInterface; begin one := TObjectOne.Create; one.DoSomething; end;

Not that this is a good idea, as the code above would cause a memory leak. By disabling the reference counting, when the variable goes out of scope nothing happens. There are some scenarios in which this is beneficial, as you can still use interfaces and not trigger the extra reference. In other words, an unsafe reference is treated just like... a pointer, with no extra compiler support.

Now before you consider using the unsafe attribute for having a reference without increasing the count, consider that in most cases there is another better option, that is the use of weak references. Weak references also avoid increasing the reference count, but they are managed. This means that the system keeps track of weak references, and in case the actual object gets deleted, it will set the weak reference to nil. With an unsafe reference, instead, you have no way to know the status of the target object (a scenario called dangling reference).

In which scenarios are weak reference useful? A classic case is that of two object with cross-references. In such a case, in fact, the object would artificially inflate the reference count of the other objects, and they'll basically remain in memory forever (with reference count set to 1), even when they become unreachable.

As an example consider the following interface, accepting a reference to another interface of the same type, and a class implementing it with an internal reference:

type ISimpleInterface = interface procedure DoSomething; procedure AddObjectRef (simple: ISimpleInterface); end; TObjectOne = class (TInterfacedObject, ISimpleInterface) private anotherObj: ISimpleInterface; public procedure DoSomething; procedure AddObjectRef (simple: ISimpleInterface); end;

If you create two objects and cross-reference them, you end up with a memory leak:

var one, two: ISimpleInterface; begin one := TObjectOne.Create; two := TObjectOne.Create; one.AddObjectRef (two); two.AddObjectRef (one);

Now the solution available in Delphi 10.1 Berlin is to mark the private field anotherObj as weak:

private [weak] anotherObj: ISimpleInterface;

Now the reference count is not modified when you pass the object as parameter to the AddObjectRef call, it stays at 1, and it goes back to zero when the variables go out of scope, freeing the objects from memory.

Now there are many other cases in which this feature becomes handy, and there is some real complexity in the underlying implementation. It is great feature, but one that takes some effort to fully master. Also, it does have some runtime cost, as weak references are managed (while unsafe ones are not).

Categories: News, Blogs, and Tips