我正在将一些遗留代码转换为 Delphi 2010。
有相当多的旧 ShortString,例如 string[25]
为什么分配如下:
type
S: String;
ShortS: String[25];
...
S := ShortS;
导致编译器生成此警告:
W1057 Implicit string cast from 'ShortString' to 'string'.
此处没有发生数据丢失。在什么情况下此警告对我来说是有用的信息?
谢谢!
汤姆
最佳答案
这是因为您的代码隐式将单字节字符串转换为 UnicodeString。它会警告您,以防您可能忽略了它,因为如果您错误地这样做,可能会导致问题。
要使其消失,请使用显式转换:
S := string(ShortS);
关于delphi - 为什么 Delphi 在将 ShortString 分配给字符串时会发出警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2121265/