4
votes

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?

2
It may be quick but it certainly wouldn't be safe.mghie
Yikes! That is /not/ something that you want to do.Nick Hodges

2 Answers

1
votes

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.

2
votes

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.