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 dfown and write it all up. At lat 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)

Tuesday, 3 February 2015

Off to Australia to talk at ADUG Symposium 2015

I’m delighted to be able to announce that I’m off to Australia in March to do some talks at the ADUG Symposium 2015!

It’s a long way to travel, but I’m really looking forward to talking to the ADUG members about Delphi XE7 in both Melbourne and Canberra.

I’ve got a couple of talks scheduled in. I’ll be talking about consuming Android OS features that are outside the scope of what the FMX framework wraps up, and also looking at creative debugging techniques.

Hopefully I’ll manage to shed the jetlag in the few days prior to the event, when I shall be enjoying the delights of Melbourne, and then after the 2 events I’ll soak up Canberra before returning back to normality.

Thanks for inviting me along, ADUG – I can’t wait to join you in Australia!

Delphi and Android services (part 3)

Once upon a time I uploaded a Delphi sample app to the Google Play Store, written in Delphi XE5 and implementing an Android service. I wrote about the published app in this post and supplied the source in this follow-up post.

There was an issue that’s been hanging around with that sample project. When pulled into Delphi XE7 and updated so it all compiled nicely, it didn’t play ball when deployed. Instead it hung.

I’ve eventually worked through the to-do list enough to take a look at the problem. For one reason or another starting the service in the OnCreate event handler caused an issue thanks to some required thread synchronisation, which no longer functions as I wanted it to.

I’ve worked around the problem by very slightly delaying the service starting by use of a one-shot timer. Then the form setup is done and dusted by the time the service is invoked and all seems to be well.

An updated download archive is available here, which contains the original Delphi XE5 project and a Delphi XE7 equivalent, which should now be functionally equivalent.

Another update has been made to the project download, which now contains Delphi XE8 support. Delphi 10 Seattle introduces its own support for native Android services, but Delphi XE8 / Lollipop made some changes that broke the demo as it was originally written. The XE8 version of the project should hopefully resolve that problem.

Wednesday, 10 September 2014

Delphi and NFC on Android

NFC is a neat technology.

If you’ve got an NFC sensor on your phone or tablet then there is a reasonable chance you’ve played around with apps like Trigger, which perform various actions on your device when you wave it over NFC tags in stickers or on key fobs etc. after a bit of setup.

So, for example, you could have an NFC sticker by the front door that has been coded by Trigger to turn off Wi-Fi and Bluetooth. With a variety of of NFC tags around and about you can set up your phone how you need it when you need it by a simple wave, avoiding a whole lot of fiddling about in the device settings.
Anyway, that’s one application of NFC tags. There are, of course, plenty more.

Indeed there have been a good number of questions in various forums asking how to get programmable NFC support in Delphi. Of course NFC is not currently “wrapped up” by Delphi’s RTL so up until now it’s been in the hands of the “creative”.

NFC tag scanning support in Android falls into 2 areas:

  1. You install an app that advertises that it can respond to some NFC tag content. When the device is waved against such a tag the app can be automatically launched. If more than 1 app is registered Android will initially launch a chooser dialog to allow the user to pick the app they require.
    Actually this support is easy enough to do in Delphi so long as you can locate a suitable import unit or two containing the required Android APIs for NFC.
  2. You run an app that permits the user to scan NFC tags while it is in the foreground and it directly responds to any scanned tags.
    This seems to be more commonly required in commercial applications and alas is much more difficult to achieve with Delphi. It falls into the category of problem that requires some Java smarts and some command prompt hackery to achieve.
    Bummer.

Anyway, I was recently looking into writing some NFC support, given the frequency of questions being asked. Part way through my research I discovered that Daniel Magin was simultaneously trying to do the same thing, primarily for a talk at Delphi Tage.

I helped Daniel out with the Java callback and command-line building trickery – that seems to be an area where I can readily add value to Android low level chicanery – and he helped me out overcoming a nasty crash bug with Java arrays of NFC data records not being surfaced correctly by the Delphi RTL.

In the end we both had some sample apps that permit NFC scanning and also, just as an added bonus, NFC writing!

You can find my solutions written up in quite some detail here:


Daniel’s efforts will also be made available very soon.

Enjoy coding up your NFC apps, everyone!

Update - Dec '15


A number of people had tried to use the code on versions of Android more recent than was current when I worked all this and hit problems with the code crashing. This was down to some inappropriate use of JNI constructs where the problem didn't originally show up but did show up as later versions of Android got more picky about things. I've remedied this issue in 2 ways.

1) I've updated the samples and code snippet in the article (it's OnNewIntentNative that has changed, FYI, in its usage of the intent JNI value).
2) However I've also devised a different sample app (for XE7, XE8 and 10 Seattle) that does much the same thing but doesn't really use explicit JNI. Instead it uses a listener interface implemented in Delphi and called from Java. The app has been slightly extended to allow the NFC support to be toggle on and off via a checkbox.

Updated samples: