tags:

views:

393

answers:

2

Delphi 2009 and above support unicode. I have few legacy pascal source files that I wish to make it compile in Delphi 2009/2010 as well as Delphi 2007 and below.

A quick and safe way is replace

  • String to AnsiString
  • PChar to PAnsiChar
  • Char to AnsiChar

Is there any utility available that able to parse .pas file and make such replacement?

+1  A: 

There is a tool for pointing out areas that might need attention:

http://cc.embarcadero.com/Item/27398

It doesn't convert it automatically, grep would do that but as mghie said it's not that simple.

Alan Clark
+1  A: 

You can use sed for that.

sed -i bak -e "s/string/AnsiString/g" *.pas

It would be a very bad idea, though. There's no reason your code shouldn't compile in all Delphi versions. The meaning of "string" has changed, but so what? Your Delphi 2007 code doesn't need to be used with your Delphi 2009 code. The DCU file formats are different, so you'd have to recompile anything you change anyway.

By changing everything to AnsiString, you're essentially rejecting everything new that Delphi 2009 offers. If that's what you want to do, you could have saved yourself a lot of money by simply not upgrading to Delphi 2009 at all. Why buy a product and then not use any of its features? Since everything else in the product is Unicode, your program's performance will go down the tubes as it continually converts between string formats. You'll also drown in compiler warnings from all the conversions.

Don't force square pegs into round holes, especially when you have a perfectly good set of round pegs sitting right next to you.

Rob Kennedy
Thanks. I will try to make my legacy code to fully upgrade to Delphi 2009/2010 and able to compile with any version of Delphi.
Chau Chee Yang
Then the first thing you should try is to not change anything at all. Test your program with the new compiler. Find out what actual problems you have.
Rob Kennedy