Why does Delphi warn when assigning ShortString to string?

后端 未结 6 1612
栀梦
栀梦 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:13

    It's because your code is implicitly converting a single-byte character string to a UnicodeString. It's warning you in case you might have overlooked it, since that can cause problems if you do it by mistake.

    To make it go away, use an explicit conversion:

    S := string(ShortS);
    

提交回复
热议问题