delphi - Implicit string cast with potential data loss from 'string' to 'ShortString' - Stack Ov

admin2025-04-18  3

I have several assignments like this (example):

string[50] := string + string

The length of string is mandatory (50...20...10...). This warning is generated:

W1058 Implicit string cast with potential data loss from 'string' to 'ShortString'

What cast can be done to eliminate this warning?

I have several assignments like this (example):

string[50] := string + string

The length of string is mandatory (50...20...10...). This warning is generated:

W1058 Implicit string cast with potential data loss from 'string' to 'ShortString'

What cast can be done to eliminate this warning?

Share edited Jan 30 at 16:50 Remy Lebeau 601k36 gold badges507 silver badges851 bronze badges asked Jan 30 at 13:07 Robe79Robe79 595 bronze badges 2
  • Why did you remove "1" (and renumbered "2" to "1")? – HeartWare Commented Jan 30 at 13:41
  • @HeartWare Because unrelated questions should be asked separately. The first question warrants its own post. – Remy Lebeau Commented Jan 30 at 16:55
Add a comment  | 

1 Answer 1

Reset to default 1

To eliminate (suppress - ie. not a fix) the warning, do an explicit type cast to ShortString:

string[50] := ShortString(string + string)

But, you are only suppressing the warning. If string (or string) contain characters that can't be represented in 8-bit in your current locale, you'll get '?' characters instead.

As you can see, it's an uphill battle to try to force the UNICODE compiler to work in ANSI mode. You would be much better off to simply convert your code to full UNICODE from the bottom up.

转载请注明原文地址:http://anycun.com/QandA/1744916878a89448.html