Why does Delphi warn when assigning ShortString to string?

后端 未结 6 1609
栀梦
栀梦 2021-01-07 18:42

I\'m converting some legacy code to Delphi 2010.

There are a fair number of old ShortStrings, like string[25]

Why does the assignment below:

         


        
6条回答
  •  天涯浪人
    2021-01-07 19:34

    The ShortString type has not changed. It continues to be, in effect, an array of AnsiChar.

    By assigning it to a string type, you are taking what is a group of AnsiChars (one byte) and putting it into a group of WideChars (two bytes). The compiler can do that just fine, and is smart enough not to lose data, but the warning is there to let you know that such a conversion has taken place.

提交回复
热议问题