Migration Delphi 7 To Delphi XE3


I have a project has just been migrated from delphi 7 to delphi XE3.
In compile still has some 4000 warnings:



W1050 WideChar reduced to byte char in set expressions. Consider using CharInSet function in SysUtils unit.
W1058 Implicit string cast with potential data loss from string to AnsiString
W1057 Implicit string cast from AnsiString to string
W1044 Suspicious typecast of string to PAnsiChar

I did not correct these warnings because I didn't have problems with the strings in the project,
but is worried whether this will affect the current code.

Responses (1)
  • Accepted Answer

    Monday, November 13 2017, 10:29 AM - #Permalink

    In your Delphi 7 project, are you using Sets of Char?

    In Delphi, sets can include a maximum of 255 elements.

    Sets of Char worked when Chars were one byte. With Unicode, now that they are two bytes in size, you will get a compiler warning if you try to use a set of Char.

    The compiler will suggest using CharInSet, which has two overloaded versions, one for WideChar, and one for AnsiChar. Here are the declarations:

    function CharInSet(C: AnsiChar; const CharSet: TSysCharSet): 

    Boolean; overload; inline;


    function CharInSet(C: WideChar; const CharSet: TSysCharSet): 

    Boolean; overload; inline;

    TSysCharSet is declared like this:

    TSysCharSet = set of AnsiChar;

    The Char in Set warning is very common when migrating to Unicode Delphi.  Although the compiler says it's a warning, if you get many warnings, then it's best to treat them as errors and fix them.


    The reply is currently minimized Show
Your Reply

Please login to post a reply.........