Tuesday, 22 November 2016

Debug logging in FireMonkey – CodeRage XI Lightning Talks

During CodeRage XI I had a couple of Lightning Talks broadcast on a subject I’ve been intending to write up for quite a long time, but haven’t quite managed to achieve: how to emit debug log messages on the various FireMonkey platforms.

I made a 10 minute video for Delphi and one for C++ looking at all the target platforms, Win32/Win64, OS X/macOS, Android and iOS, showing the logging options and then looking at how to view log output.

Unfortunately I got a bit caught up in some work and didn’t publicise this ahead of the conference, so I think not many people were aware of them.

If you want to see the short videos after the fact, you can see them below or on YouTube:

Debug Logging in Delphi FireMonkey Apps

Debug Logging in C++ FireMonkey Apps

You can look at the supporting (short) slideshows on SlideShare (ignore the funky bullet point symbols – something was awry in the slide template when I made the slides):

Debug Logging in Delphi FireMonkey Apps

Debug Logging in C++ FireMonkey Apps

The simple sample projects are also available to download:

Friday, 9 September 2016

Android callbacks wrapped by FireMonkey

A couple of years ago (exactly!) I posted on this blog about an article I’d written on accessing NFC tags from Delphi Android applications. At the time this was quite an involved exercise, requiring custom Java code to be compiled and linked in to the application in order to respond to the pertinent Android callback, Activity.onNewIntent. Indeed, Delphi versions XE5, XE6 and XE7 all have slightly differing capabilities, with each new release making certain Android operations rather easier.

While catching up on what’s new in recent releases of Delphi I realised a change had been snuck into Delphi 10 Seattle that makes the whole NFC exercise much more straightforward now in Delphi. What this change means is:

  • No more custom Java code required!
  • No more linking in a custom Java library file
  • No more activity custom subclassing!
  • No more debugging obstacles!

This change seems to have gone in completely under the radar*, escaping the attention of the documentation department, so I thought it best that I brought it out into the open.

It turns out that the key activity callback that NFC foreground dispatch relies upon (Activity.onNewIntent) is now hookable from Delphi code (with the right know-how) and so all the Java shenanigans can be put behind us (at least in the context of NFC access). This callback is used in Android in all sorts of other scenarios as well, so if you find a requirement for responding to onNewIntent then Delphi 10 Seattle (and later) makes this something of a doddle.

I have updated the article to show the more direct means of accessing NFC from Delphi 10 Seattle and later and provided corresponding updated samples for Delphi 10 Seattle and Delphi 10.1 Berlin. You can find the full details and code there.

In short, though, new intents are picked up in the FireMonkey activity’s onNewIntent method and sent into the RTL cross-platorm messaging system. You can write message-receiving code to pick up new intents and process them, This intent messaging is done via an additional (and seemingly undocumented) use of the Android-specific TMessageReceivedNotification message.

If you are playing with NFC cards in your apps you can simplify the setup very nicely in the most recent versions of Delphi.

Just to round this topic (given the blog subject) off I’ll also mention that another activity callback, onActivityResult, is also covered by FireMonkey and has been since Delphi XE6. This is also wrapped up in the same messaging system, though this time with the TMessageResultNotification message.

I showed an example of how to use this to pick up information about a scanned barcode (scanned by the popular and open Source ZXing, or Zebra Crossing, barcode scanner app) in an article about launching various activity types back in April 2014: Launching activities and handling results in Delphi XE6 Android apps.

* Update [16/09/2016]: I have since discovered that both Delphi 10 Seattle and Delphi 10.1 Berlin ship with an Android intents demo that does in fact utilise this feature. The demo is located at:

  • Delphi 10 Seattle: %PUBLIC%\Documents\Embarcadero\Studio\17.0\Samples\Object Pascal\Mobile Snippets\AndroidIntents, documented here
  • Delphi 10.1 Berlin: %PUBLIC%\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Mobile Snippets\AndroidIntents, documented here

The most up to date version of the demo can be found in the Delphi 10 Seattle Sourceforce repository or the Delphi 10.1 Berlin Sourceforge repository.

Thursday, 1 September 2016

Speaking at the SDN Event

All the preparations are nigh on complete and this evening I shall be on a short aeroplane ride to Holland (or The Netherlands, if you prefer) to present a couple of Delphi talks at one of the SDN’s big SDN Events – full agenda here. I’ll be in good company as also speaking on the Delphi track will be TMS Software’s Bruno Fierens and also Bob Swart.

I’ve spoken at User Groups regularly but this is the first opportunity for me to talk to Delphi developers from further afield at a conference since April 2015 when I was at the ADUG Symposium, speaking in Canberra and Melbourne.

SDN events are always friendly gatherings and I’ve spoken at a few of them over the years: 1997, 1999, 2002, 2005, 2006 and 2012.

This time around I will be speaking on two of my favourite subjects: creative debugging techniques and accessing the Android OS API. Naturally I’ll be using the latest and greates version of Delphi as a vehicle for the talks, and I’ll be trying to squeeze in as many technical tips, tricks and techniques as I can into the 2 hour-long sessions.

For those attending the event tomorrow (2nd September, 2016) I’ll see you there!

Thursday, 23 June 2016

Live Templates (née Code Templates)

Over the years since Delphi 3 various people have written about aspects of Code Templates and Live Templates, but not particularly recently. I find Code Templates fabulously helpful and Live Templates add some real power into the mix.

About six or seven months ago (November 2015) I did a User Group talk on Live Templates and it seemed to provoke some reasonable interest. Since then I’ve been trying to find a suitable time window to sit down and write it all up. At last I have had a couple of days to gather my thoughts and get it all down on (metaphorical) paper.

For the benefit of those who haven’t considered creating Live Templates to help their productivity, or who have forgotten about the feature over time, please feel free to peruse Code Templates and Live Templates over on my web site.

Sunday, 3 January 2016

Some Delphi and C++Builder articles

My blog editor of choice is proving to be a little quisquous at the moment.

Historically I have used Windows LiveWriter, part of Windows Essentials (whose development stopped in 2012, but was still available here (web installer) and here (offline installer)). This worked well, but at some point over the summer it stopped working with the uprated authentication requirements of Google’s Blogger. Fortunately though, it has just been open-sourced and is now available as Open Live Writer here.

However while one issue I immediately hit with this new version has been fixed, I have still yet to successfully connect to my blog with Open Live Writer. Fingers crossed….

So until the initial set of issues are worked out I’ll post articles and link to them by short manually entered blog entries here.

This post is mostly to point at a short article I’ve put together that brings to the attention of those who are interested the easy means to lessen the size of your Windows application’s executable file.

You can find the article here: Trimming The Fat - Smaller Windows .exe Sizes With Delphi And C++Builder.

[Update 20150105: I've made some changes to the advice in the Trim the Fat article (clearly marked) after some input came through from a helpful reader.]

Before signing off I want to mention a couple of other posts that recently caught my eye:

Daniele Spinetti has very recently worked out the solution to a bug he encountered with Android background services in Delphi 10 Seattle, which meant that the TLocationSensor component doesn’t function when used in an Android service data module. The problem has been identified and described in his (very) recent post. This will be a useful addition to those trying to use Android services to accompany Jim McKeeth’s offerings:

Daniele also has a post showing how to use AdMob insterstitial adverts in Android apps as an alternative to regular banner ads.

Some posts from Chee Wee also stood out as interesting:

Happy New Year!

Thursday, 6 August 2015

Delphi Stuff

I’ve been rather quiet on here lately. But I’ve kept my eyes open on what things have been appearing on the ARPANET relating to Delphi. I kept a list of things that piqued my interest.

On the off-chance you’ve missed any of these and might find them of interest, here’s a list of Delphi stuff.

Open source code bases:

WinSoft XE has released their commercial NFC Library for Android 2.0 for Delphi/C++Builder XE7 and XE8 – see FMX Express mention here. This is a ready made approach to NFC, which might be preferable to the do-it-yourself approach previously (and still) freely available:

One of the stalwarts of the old Delphi team, Charles Jazdzewski, aka Chuck J (also aka DJ Jazzy Chuck aka The Chuckinator aka Chuck-a-luck-a-high-chuck-a-hiney-ho), has been posting some nostalgic memories about the origins of the Delphi project:

Old Borland videos:

Borland Old Testament Histories by Verity Stob

  1. Book of Anders (1996)
  2. Yocam hokum (1998)
  3. Book of Yoc-am (contd.) (1999)
  4. Borland Revelations (2004)
  5. Borland's Delphi Goodbye (2006)
  6. A reading from the second book of Codh (2008)
  7. Sons of Kahn: The Apocrypha (2010)
  8. The Sons of Khan and the Pascal Spring (2012)
  9. The Sons of Kahn and the assembly language of the internet (2012)

Not quite Delphi stuff:

Unlikely to actually be interesting to anyone other than myself, but I was following a chain of posts on the old Windows Error Reporting tool, Dr Watson:

This led me back to a post by Matt Pietrek (who worked for Borland and wrote TDump and WinSpector) from his awesome Under The Hood column:

and right at the end he included a link to one of my various Undocumented Easter Eggs pages :o) That made me smile!

Wednesday, 4 February 2015

Two Decades, Eh?

Well, well, well, it turns out I’ve been working for myself for two decades now! I left Borland in January 1995, thinking I could manage maybe about 5 years if I was lucky and did well before I got another full time job. And now we’re in 2015! How time flies when you’re having fun :o)

Oh yeah, and a couple of weeks after I left my last employed job Delphi 1 came out, and that was awesome too! And my oh my, it’s nearly the 20th anniversary of the launch date of this great programming language: Feb 14th 1995.

To celebrate this milestone, Embo is hosting an online Delphi Week leading up to the Feb 14th launch date anniversary, Feb 9th to 13th. You can read more about it on this community news post and this community event post. Do read up on it and try and join in – it should be fun :o)