Posts Tagged ‘Unicode’

Migrating to Unicode

Wednesday, July 20th, 2011

I recently started migrating my current client’s project to Unicode in a proof of concept application whose purpose was to decide on whether or not to upgrade to the latest version of RAD Studio.

The project is just under a quarter million lines of code to give you some perspective on it’s size, and it’s one of the most complex systems I have ever worked on.  It uses hcOPF extensively, incorporates tons of business logic, and it monitors and controls external serial devices.

Anticipated Challenges

I anticipated that the Serial port library used would be one of the most challenging items to port.  It only supports up to Delphi 2005, and doesn’t appear to have been updated since October 2003.  That said, the library was in use in the previous version of the product and proved itself to be reliable, so I chose to adopt it for the new release and had the same results even under Windows 7.

Other third party components used are the JEDI JCL/JVCL, hcOPF, DevExpress, TMS and PngComponents.  I didn’t anticipate any issues with the JEDI, DevExpress, or TMS components since they have been supporting Delphi releases almost as soon as they become available and have a good reputation in the community.  I knew that when EMB acquired the PNG components library they made some changes, in addition to trying to remove the old project’s code off of the Internet.  It took me some time to find the PNGComponents for Delphi 7 when I developed the app, and I must say it implements great designers, and is a pleasure to use.

Approach

Since this is a pilot project, using the current source, I wanted to make minimal changes to Unicode enable the application, in order to reduce the testing burden and likelihood of breaking proven code.  I also wanted to keep the source compatible with Delphi 7-2007 in case we chose not to upgrade, without having to discard all the work done for Unicode support in case we decided to upgrade at a later date.

I started by creating the D15 projects for all the components used and getting them installed into the IDE.  This proved to be my first road block as documented.  It took a blog post, a couple calls to tech support and one to sales before I managed to get a timed key to enable Delphi XE’s command line compiler and all of the features of the product.  My advice to anyone attempting to perform an upgrade is to contact EMB to get a timed key to begin with.  I would also advise to download the Delphi XE ISO from here.  When I attempted to upgrade my installation using the timed key, it kept complaining about not being able to resume a broken download, and it didn’t matter what option I chose, it would just repeatedly show the same dialog which doesn’t even tell you what download is broken.  After uninstalling Delphi XE I got the same error attempting to re-install the product.  Only when I installed from the ISO was I able to get the product running again.

Then I read Cary Jensen’s migration paper, and that from Nick Hodges.  I enabled all the Unicode compiler warnings as Marco Cantu recommended and paying special attention to <W1058 Implicit string cast with potential data loss from ’string’ to ‘AnsiString’> errors I proceed to go through the code and decide what needed to remain an AnsiString and what changes were needed to minimize any implicit conversions.

The Reality

The new PNG support in Delphi does not contain the TPNGImageList and TPNGCollection components.  I had used both in my application.  I attempted to compile the D7 version, and quickly abandoned that when I encountered several ‘cannot assign to left side’ errors.   Prior to discovering that  Uwe Raabe had submitted an update to the components to CodeCentral, I changed my application under D7 to load items from Resources. In some cases though, I was using components that required Imagelists so finding Uwe’s port saved a some effort in converting them for use under Delphi XE, and kept my source code compatible with D7.  Thanks Uwe!

To me this exemplifies one of the primary difficulties in upgrading projects to a new version of Delphi.  One that Embarcadero, likes it’s predecessors, doesn’t seem to understand, because if they did, why would they have removed the PNGComponents open source project?  Surely developers don’t upgrade their version of Delphi simply for new image support!  It would also be foolish to think you can stop the sharing of what was once open source on the Internet, or that attempting to do so wouldn’t give you a bad rep with prospective customers.  The reality is that there are Delphi developers out there who use old versions because they don’t like .NET, think the old IDEs are leaner and do everything they need, or are locked into their current IDE because of the sheer size of their code base and thus the magnitude of their porting effort, or because they don’t have source for their components.  By making the migration more difficult, these customers are going to be left behind no matter how many BOGO offers are made.

Anyway, I digress.  I made liberal use of CharInSet(), converted my serial component to use AnsiString/AnsiChar and made numerous other little changes and was amazed that it all ran just fine.  Porting this particular project to Unicode was much easier than I anticipated.  While the product still has to under go complete testing by the QA people, I am happy to report that the unicode migration project took less than the week I estimated, and none of the potential problems I was concerned with have materialized.  For those of you that haven’t taken the leap, I would encourage you to do so.