Friday 19 December 2014

Delphi Cookbook review

A few people have reviewed this book already but for various personal and work commitments, reasons, I've been unable to review the book until now.

It's been many years since a really innovative Delphi book came out that was worth taking a look at. Delphi Product Manager +Marco Cantù's annual book is always an excellent source of up-to-date reference, and Coding in Delphi by the former Product Manager +Nick Hodges was a worthy giveaway to those who purchased recent versions of Delphi.

Delphi Cookbook was written by an author I'd not come across in the Delphi community before, +Daniele Teti. It reminds me of some of the O'Reilly books I have read in the past that, although they don't assume a certain level of knowledge and explain things well enough for beginners, you get much more out of them if you do have some language experience. Indeed, Daniele explains up front in the lengthy preface that it is not aimed at beginners.

The book contains 50 "recipes" covering not only VCL Windows projects, but also cross-platform development using FireMonkey, for Windows, Mac, iOS and Android. It was written alongside Delphi XE6 and so already is one version out of date, but it is not much of an issue in this case because the recipes work much the same across all versions (although XE4 is the minimum required for the FireMonkey cross-platform code).

The first chapter, Delphi Basics, is a real eclectic mix of topics, ranging from the relatively new VCL Styles to parsing XML and JSON, from Windows Services to really old topics such as associating file extensions. These are simple to follow and some, especially the XML and JSON topics, are useful building blocks for later on.

On the whole, the recipes are enjoyable to follow and Daniele has done a good job with the downloadable examples so you can see the ideas in action when compiling them in Delphi.

There is a slightly odd flow to the book; for example, chapter 2 discusses reasonably low-level concepts like RTTI, anaonymous methods and class helpers; this is followed by chapter 3 which discusses styles in FireMonkey, and chapter 4 which then goes low-level again with multi-threading using TMonitor and TEvent.

Probably the most useful chapter for me, and possibly for many now Delphi has entered the mobile marketplace, is chapter 5, which covers writing the server-side application or service, for your remote applications to communicate with. This is neatly followed by a chapter on the mobile basics, many of which are already covered by the examples and demos provided with Delphi. However, chapter 7 also takes you further into Android and iOS platform specifics.

I like Daniele's informal style which sets the tone that this book is really about exploration and fun, rather than about following a "recipe" to the letter. He is often honest in his appraisal of a Delphi feature, which is refreshing, but it shines through that this was a labour of love about a development environment about which he, and his prospective readers, are passionate.

Without the advent of the mobile development in Delphi, I don't think this book would have taught much new to a seasoned developer. But there is plenty of well-explained content in here for everyone to have something to learn. At the very low price it is being offered for, it's a good go-to book to have in your library.

Friday 17 October 2014

Delphi development update

Hi everyone,

I can't believe it's been over a year since my last posting. My last post was having a moan about the cost of Delphi XE5, coming from XE4. Well, as many pointed out to me, the Software Assurance plan was the way to go and I'm now happily running on Delphi XE7 and enjoying being on the latest releases of Delphi as and when they emerge.

I know the whole SA/Recharge issue is a hot topic amongst Delphi developers, but I've covered that already and, as a successful business which uses Delphi heavily, the SA plan is actually a reasonable price to pay for the benefits we get from each new version of Delphi. So let's leave that discussion to the forums, for now.

I really wanted to mention 2 things today.

Firstly, using Delphi XE7, we have had our first app successfully submitted to the iOS App Store. I can't say too much about it yet because we want to give our customers the first details. But I have to say that I submitted the app to Apple 3 weeks ago, thinking the whole process would take months, knowing how difficult I've heard it is to get an app approved. Within less than 2 weeks, my app was approved, first time, and is currently in the store. Written entirely using out-of-the-box Delphi, on the FireUI framework. Communicating to a Datasnap Server written also entirely in Delphi. This is terrific for us and we have been able to re-use so much existing code for the app that would have had to be rewritten had we chosen another mobile development framework.

Secondly, I have a copy of the new Delphi Cookbook by +Daniele Teti which I have just begun and will post a review of within the next month. It's written in an informal style making it an easy read, and all of the example code is available to download if you buy the book.

Having used and evangelised Delphi for the past 20 years, I thought I knew everything there is to know, but there are some nice topics that I've encountered already that have explained something new or different, and it's always good to learn.

Happy coding.

Wednesday 18 September 2013

The rising cost of being a Delphi developer

If you review my previous postings over the past few years, you'll notice that I'm overwhelmingly positive about Delphi, Embarcadero and the quality of the software I can release because of them.

I subscribe to Delphi Feeds, as any self respecting Delphi developer should, and I read a lot of articles where opinion varies wildly. Differences of opinion are important, no matter what the subject. From the MVPs who can only write positively about Delphi and RAD Studio, to Jolyon Smith who is probably the most vociferous voice regarding the direction of Delphi and Embarcadero (and whose opinion I almost never agree with but would fight for his right to express it).

However, for the first time recently, I agreed with one of his posts. And I wasn't alone. And other Delphi writers were also expressing the same opinion: New releases of Delphi/RAD Studio are becoming prohibitively expensive.


Now, we write enterprise level software and the cost of Delphi is not significant in terms of our turnover. However, Delphi markets itself not only to enterprise ISVs, but to anyone who wants to write software simple and effectively. It does this well, but recently I feel that it's only us ISVs who can afford to keep buying the increasingly regular Delphi releases. They don't do updates any more, they're full scale releases.

They're good releases too. Personally, I use XE3 and XE4 Enterprise for our Windows desktop software, and for the iOS mobile app that we sell to complement it. Given that I had purchased a licence for XE3 Enterprise in 2012 for £800, the cost to upgrade to XE4 was in the region of £400. This caused concern in blogs at the time: an upgrade for 50% of the cost of the last version. But for us, the layout was well worth it for the effort that had gone into the iOS framework. And I was on the beta testing panel for that, and believe me, they made a lot of fixes before release.

And now, XE5 is released, offering us Android development as well. And the quote from my local reseller? £903.24 + VAT (£1083.60). Or from Embarcadero's online store? £892 + VAT (£1061). For an upgrade! This beggars belief. As The Delphi Hater's article says:

The logic is - If you buy XE5 you get XE4 for free. If you buy XE4 and didn't get SA, you are screwed.

I did receive an email a few days later offering me 20% if purchased directly from Embarcadero Developer Direct, but that's still £850, effectively knocking off the VAT.

And why do two of those links from above quote the upgrade price in the US as $499? And some suggest that the upgrade from Delphi XE3 to XE4 only cost them $49? Is the UK/Europe being ripped off again?

Note that I've had the Enterprise versions all along, I've not had to jump up a level. I've also never (so far) taken out the support & maintenance contract, which makes me a bloody idiot. :)

Worse still, the ADUG article has this to say about the changes to Delphi for iOS for iOS7:

Statements today from an Embarcadero representative on a public mailing list indicated that the soon to be released update providing support for iOS7 will be for XE5 only, XE4 users will not receive it.

If this is true, this is an outrage. All along, we've been led to believe by Embarcadero that new styles would be made available for iOS7 when the time comes, there was never any suggestion that this would come at the cost of a new version of Delphi.

So for the first time, I find myself deliberately not purchasing the software I have staked my career on, and which I need to deliver Android apps using the codebase and experience I've built up over 15 years. Some may say that I am finally seeing what they've always been saying, to which I only partially agree. They have to make their money back somewhere, but you can't charge full price for an upgrade.

I'm interested to hear what prices other people have been quoted, both for new and upgrade licences?

Perhaps Embarcadero should let me buy a support licence, seeing as I purchased XE4 in the past few months, which would then, in theory, give me XE5?

I should re-iterate: for new users, sure it's expensive, but you're buying an IDE and 20+ years of experience, to develop on multiple platforms. I'm not unhappy with that price. But for an upgrade to cost so much, when I'm upgrading from a version I purchased earlier in the same year? No.

Wednesday 17 April 2013

Initial thoughts on Delphi XE4 - iOS development

So the main thrust of my blog entries in the past few years have been about how I've wanted to make the leap from Delphi 6 to the latest version, currently Delphi XE3. As you may have read so far, we're now there and it has brought us so many benefits that I have promised I'll post about later.

In the meantime, because of purchasing XE3, I've also been allowed to take part in the beta testing of Delphi XE4, which many are referring to as Delphi for iOS.

I must mention that I have specifically given permission to discuss this by Embarcadero, and that any thing I raise now is still under pre-release and subject to change. This also isn't a critique of what is there or what is missing, more an overview to help answer any questions you may have about what is coming.

A point that confused me before taking part in the Beta was "is this going to be just an iOS development tool, or is the next version of Delphi"? The answer to that is clearly the latter. This product will be launched as RAD Studio XE4/Delphi XE4/C++ Builder XE4, and will be a complete version of your favourite development tool. It still allows for Win32, Win64, Mac and Metropolis projects as XE3 does, with the new addition of iOS Mobile projects, using Firemonkey.

When you start a new project, you are presented with an on-screen representation of the iPhone canvas.



iOS project in Delphi XE4

On this screenshot as an example, you can see a standard TButton, TListBox and TToolbar, all of which are styled with Firemonkey to appear as native iPhone controls. The IDE allows you to rotate this view, as well as select different form types so you can develop for iPhone 5 and iPad.

This appears on the XCode iOS Simulator as:



Project on the XCode iOS Simulator

My demo application has a TClientDataSet which is used to store local settings, and uses DataSnap client components to communicate over the internet to a DataSnap server running in my organisation. All of this technology has been available in Delphi for some time but it is crucial that this is working for enterprise iOS apps, and it is working great.

Unlike Delphi XE2 which used the Free Pascal compiler to generate the iOS code, XE4 handles everything natively. You still, of course, need an intel-based Mac running Lion or Mountain Lion, and like with Mac OS development, Embarcadero provide the Platform Assistant (PAServer) which runs on the Mac. Your Delphi project will communicate with the PAServer on the Mac (as set in Project Options, see screenshot below), which in turn communicates with XCode via the command line to deploy your project in the iOS Simulator or onto your iOS Device.


If you have been using any recent version of Delphi or RAD Studio then the IDE is as familiar as ever, which makes this such a great opportunity for us long-term Delphi users to start writing iOS apps. A great job has been made in getting "styles" together for the iOS controls, so that your TListbox can be styled in a variety of different native and expected ways. The TButton, too, has dozens of style options that comes with recognisable images so that your app can appear as native as you need it to be. Of course, if you want to eschew the standard styling and go your own way, Firemonkey gives you the freedom to do that.

As each pre-release version has been issued, so have more and more demos, and the documentation is improving, so there is plenty of good sample code to show you how to use the camera, the Share features, accelerometer, compass, etc.

There is plenty more to talk about this exciting new version of Delphi, but we are still in the pre-release phase and I'm sure there's more to come.

Wednesday 27 March 2013

Migration to XE3: Almost there

Two months back, when I was replacing all of data layer components in Delphi 6, in preparation for the move to Delphi XE3, I never imagined that part would actually be the most time consuming. I am writing today having fully completed the software migration over to XE3. (There are still some utilities and bespoke projects to be done but these are small projects that take little time and wouldn't affect the launch of a new version of our standard package).

We have still to entirely functionally test the software for any run-time issues and unexpected behaviour changes, but our entire software codebase is now ported to XE3 and running well. The bottom line is this: it was much easier than I thought it would be.

As I mentioned in my previous post on the migration to ADO, the longest part of this process has been writing out the old components and replacing them with the dbGo ones. Obviously there is a good case here for better data abstraction, but time was limited and we had to get the job done so we did it the manual and long way. Maybe that's something we can work on over the coming years but for now, the job is done and the results are good.

Most of the run-time issues we've seen are actually database-related, so nothing to do with XE3, but more to do with subtle differences in the way ADO and ODBC work, as well as syntactical differences in the components.

As for the XE3 compilation, the bulk of what we encountered was to do with the Unicode breaking changes from Delphi 2009. This was largely covered in several white papers by Marco Cantu, Cary Jensen, Bob Swart, etc when Delphi 2009 was released. My colleague and I read the papers and agreed on the recommended approach that we move to full Unicode support, rather than replace String with AnsiString, PChar with PAnsiChar, etc.

Although our software is almost exclusively UK based (because of its nature), and the fact that the data we have to submit to HMRC (the UK government tax agency) is only allowed to contain ASCII characters, we found that it was easier for us to move forward with the native Delphi types than to try and maintain the older Ansi types.

The only exception to this, where I really had to put my brain into gear, was for some API headers that I had written in Delphi for some older hardware DLLs. The hardware communication stopped working with Unicode types, so I switched those back to Ansi types and everything worked as it did before. Also, we have some units that implement some well known encryption routines (SHA-1, Base64, MD5), and these all needed attention to prevent them from using Unicode.

Here is a summary of the things we came across most often:
  • Implicit string conversion warnings.
    90% of the time this was simply because different variable types were being used. In almost all cases for me personally, it was the use of the ShortString type that raised this warning, and so I made the decision to just do away with ShortString all together and always use String.
  • WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit.
    Another compiler warning well reported in the Unicode conversion white papers, this is simply as case of changing the syntax of testing for a Char in a set of Chars.
  • Syntax error using local settings constants.
    Having made much use of constants such as ShortDateFormat, ShortDayNames, etc, these now have to be prefix with the FormatSettings global variable.
  • [dcc32 Hint] Inline function 'TFont.GetStyle' has not been expanded because unit 'System.UITypes' is not specified in USES list.
    The name of the class and method often changes, but this compiler hint is always resolved by following the instruction: add UITypes to the unit's Uses clause.
  • Version Info and Release v Debug.
    This one really caught us out and I wasn't aware of it until we switched to XE3. Firstly, projects now have separate Release and Debug build configurations, which means any project options you have need to be set individually.

    Not a problem for the most part, but the Delphi 6 project file's (.dpr) VersionInfo doesn't migrate across correctly into XE3. The Language Locale reverted back to English (United States), where we had previously had it set to English (United Kingdom). Also, the information only came across for the Release configuration, so needed to be redone in the Debug configuration. We use the information in here for checking which modules can be loaded at run-time so it was important that it was set correctly in both configurations.

    Personally, I don't like having to switch to Debug mode into order to be able to set breakpoints and step through code, and then have to remember to set it back to Release mode for the final build. I guess you have the option to set both configurations to use the same Compiler settings, but this would add unncessary debug information to the compiled release executable, so I can see the point of having 2 options. I suppose it is just a case of having to get used to a new routine.
There were some nice new features that we were able to make use of and throw out some more third-party components and units, which I wasn't expecting. The native TZipFile type meant we could support Zip files without relying on a third-party unit or tool. And the RegularExpressions unit meant I could also get rid of an old unit written for Delphi 6 that enabled it to handle regular expressions.

I was also able to get rid of the manual manifest files I had created to allow Windows theme support, as this has been a project option for a long time in Delphi, but obviously not way back in D6.

I'd like to talk about the IDE and performance changes but I will save these for another post. But for now, I'm delighted with how well the migration has gone and the results we have. If you're thinking about doing it, but had the same reservations I me, then I can now say from experience that it isn't as bad as you think and it's worth the effort.

Tuesday 5 March 2013

Migration to XE3: ADO complete

If you've been following this (often tortuous) path of how we are going to migrate our 14 year old software from Delphi 6 to XE3, you'll know that our only real stumbling block was the fact we were using the now defunct ODBCExpress database component set. We needed to move to a different tool that was supported by XE3, and so we finally decided upon the dbGo ADO components that have been native with Delphi since Delphi 5.

It is with great satisfaction that I can report we have now moved all of the standard code over to the ADO components. There are still some bespoke utilities that we will come to later, but for now the standard software is up and running using ADO. It took us a little over two weeks of solid work to code out the old component set, and this was all done in Delphi 6 so that we could get ourselves to a point where, in theory, everything was working the same as before.

I'm delighted with the speed improvement we've seen in database access. I'm not sure whether this is because ADO is an improvement over ODBC, or the drivers are better, or whether the ADO components are more effective than the ODBCExpress components were. Probably a bit of everything.

It's kind of funny timing that just as we finished this refactoring, Embarcadero announced the purchase of AnyDac (now called FireDac). A few years ago when I first blogged about needing to move away from ODBCExpress, a few correspondents recommended AnyDac. I've heard nothing but good things about it, but ultimately I wanted to get away from a non-native third-party component set which is why we opted for dbGo. I'm pleased with this decision still, but I certainly would have given AnyDac a closer look had I known that it would become standard issue by the time we got to XE3.

I'd like to take the opportunity to thank my colleague Andrew for his collaboration on this task. I've been putting this off for a while now but having another pair of (safe) hands has given us the confidence to go for it, and Andrew has effortlessly ploughed through the same tedium as I have in order to get us to where we need to go.

So now, the next step is to open the code in XE3 and work through the Unicode warnings. I'll keep you posted.

Thursday 14 February 2013

18 Years of Delphi

As many other Delphi bloggers have already written about, today marks the 18th anniversary of the release of Delphi 1.  This is a significant achievement given the years of speculation about Delphi's demise, and it certainly has been through some rough times.

However, it genuinely feels like good times again at the moment. So much so that we at Carval have committed to the latest version, and are looking forward to the Delphi mobile version that is in the pipeline.

It does, though, make me realise how long I've been doing this job already. I had a lucky break and was given a project in my final year at Manchester University that used this brand new 16-bit development platform, called Delphi. It didn't take me long to upgrade to Delphi 2, and here I am 18 years later having made a career from it.

Happy birthday, Delphi. Congratulations to those at Embarcadero who are still as involved now as they were on Day 1.