A Rough Tool from Roger Connell.
With the introduction of Unicode support in Delphi 2009 code gear changed the generic definitions of String, Char and PChar and while they still offer compiler switches to support old short string code (Delphi One string type) they did not provide a switch to support Longstring data from ?Delphi 3? to Delphi 2007 which may be compromised by the Unicode implementation. I made extensive use of the Delphi LongString in string manipulation routines, communications and persistence framework and I have much code that cannot tolerate and in fact does not need Unicode Conversions as I am mostly dealing with byte streams which may contain Unicode but can be handled as bytes. The old Longstring of Byte sized Chars still exists but it requires the generic types to be re-specified as AnsiStiring, AnsiChar and PAnsiChar. Doing this on a file by file basis became tedious and I now have a tool. Others might be interested.
The conversion reflects my programming style and quirks so you may need to tweek the output or modify the converter so you have the code. If I was to revisit the code now I would replace PChar(SomeVar) with PAnsiChar(AnsiString(SomeVar)) to cope with the situation PChar(SomeFunctionWhichReturnsAString). CodeGear have been very helpful and in the context AnsiString(SomeFunctionWhichReturnsAString) AnsiString is implemented not as a cast but as a converter function. But as I said all my code is converted so this is unlikely I will revisit the converter.
Will this work for your code? Probably not out of the Non Box but you may only be left requiring only few little tweaks. If we take a bit of code many of us have an interest in "Indy". When I found my D2009 applications exhibiting problems with mailing attachments that early Unicode Adapters flagged in 2009, I spent an hours sure I had the latest D2009 updates and trying to get the latest Indy (which may or may not have fixed this problem).
When it all was looking too hard and I might need to stay with D7 I decided to try converting the non Unicode version of Indy 10 I download years ago. An hour later I had compiled the whole Indy source in D2009 and my applications work as they do in D7 including emailing file attachments.
I have revisted this converter on a number of occasions and converted a couple of large legacy programs. The interface is rubish and even I have trouble but the results have not failed me. I have had to fix only two problems and they both were a result of passing encrypted AnsiStrings into TString Objects which activated an unwanted Unicode conversion.
Back up before using and take care
There does seem to be a problem with the converter if the DPR is already converted to D2009 in that a couple of odd characters are inserted at the start. I suspect this is the Unicode Code Page flags.It is easy to delete them.
The code does a global replace on .pas and .dpr files
It will do
Zip of Code and Executable The file includes the latest executeable, all source code and my function pick up file ISDelphi2009Adjust.pas
Roger has been an active member of active member of the Australian Delphi Users Group and tries to make useful a contributions to the Delphi community in Australia.
The company accepts no liability for any alleged or actual damage arising from the use of any of these products or this information.
INNOVA Solutions Pty Ltd - ACN
081 449 836