0

What would be the best process to convert a very old ANSI charset based Win32 application to UNICODE? The source code is currently compiled with Delphi7. Would it be best to make this conversion with which Delphi version? I have currently a license for XE6 version, is it worth of using that one?

There are plenty of .pas and .dfm files so AI would be the preferred method.

The code is using both STRING (oldest) and ANSISTRING, pchar, TStringList, TStreamFile. The code is compatible with all Windows versions from Windows95 to Win11.

This is just a tiny example how strings are used:

function LocalizeGUI.LanguageCodeStr( code :string ): integer;
var
  rowlist : tstringlist;
  st,j,i : integer;
  alang: ansistring;
begin
st := 0;
if code = '' then code := Setting_ActiveLANGUAGE;
     for i := 0 to languages.count - 1 do begin

     alang := '';
     RowList:= StrParse(Languages.strings[i],'=');

        if (rowlist<>nil )and (rowlist.count>0) then
          if uppercase(rowlist.strings[1]) = uppercase(code) then st := i;

       RowList.free;
     end;

     result := st;

end;
7
  • 1
    What does the app do? Is the character encoding a central feature or marginal? What is your definition of best? What happens when you try it with any version you have available?
    – teapot418
    Commented Jul 16 at 9:44
  • The app reads tons of Ansi txt files and handles these on GUI custom components.
    – Tom
    Commented Jul 16 at 9:48
  • 1
    Based on how poorly (Why using st when result would do already? Why not exiting the loop upon a match?) and inconsistent (indention, spaces, unused variables) this code alone is written I suggest you manually go through all that, as you potentially find lots of quirks and bugs anyway. Or ruin it with AI right away.
    – AmigoJack
    Commented Jul 16 at 10:43
  • 3
    "AI would be the preferred method" Forget it.
    – Jan Doggen
    Commented Jul 16 at 13:52
  • 1
    If you were using the generic types, String, PChar, etc then most code will migrate to Unicode with little to no change. If you are using AnsiString/PAnsiChar explicitly, they will continue to work as-is, though you may get compiler warnings/errors about data conversions, etc. The best option in your use case is to make use of TEncoding to convert ANSI data to Unicode as soon as it enters your app, and vice versa when leaving your app. Things like TStringList, TFile, etc have TEncoding overloads available. Process strings only in Unicode (as UnicodeString or UTF8String) Commented Jul 16 at 17:17

1 Answer 1

4

Embarcadero provides a very comprehensive site containing lots of information about how to migrate Delphi or C++Builder apps in different ways (e.g. Unicode, x64, databases, etc.):

Migration and Upgrade Center

In the section for Unicode migration you can find the Unicode Statistics Tool (for downloading it a free CDN account is required):

This Unicode Statistics Tool will assist you in collecting useful statistics for the time and effort needed to migrate your Delphi applications to Unicode.

The tool reviews your code and tells you where and what you will most likely have to change. This will at least give you an estimate of how many lines need to be reviewed.

So together with the other resources available you should have a good grasp of what you really have to do or change for a successful migration, whether manually or AI-driven.

Regarding you question about which Delphi version to use for the Unicode migration process:
It doesn't really matter at all, each Unicode enabled Delphi version is sufficient (that is, Delphi 2009 to 2010, XE to XE8, and 10.0 to 12.1, at the time of this writing). What matters more in this case is, what 3rd party components used in the original project are available for which later Delphi versions. But that's a different topic...

3
  • 1
    Thanks for these awesome solutions! Unfortunately I was not able to login to their old aspx based CDN support portal to download the tool as their pwd reset is not working and I was unable to create new accounts as server timed out. It interesting that when working with old things always something weird happens :)
    – Tom
    Commented Jul 18 at 4:45
  • 1
    @Tom The Unicode Statistics Tool project will be moved to github.com/Embarcadero soon! Thanks for the feedback. Commented Jul 19 at 11:09
  • Excellent, thanks, please let me know here when its available for download there :)
    – Tom
    Commented Jul 19 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.