looking how to suppress a warning from the compiler that says possible data loss,
st:= copy(str,0,2);
where st is string[2] and str has more then 2 chars.
and copy is defied as from str return a new string that is a subset from 0 , 2 places.
This will suppress the warning, but beware the underlying issue is still there: Converting from Unicode to AnsiString can cause lose of data.
st := ShortString(Copy(str,1,2));
And don't forget Delphi stings are 1-based, the first char in the string is 1, not 0.
If you just write:
st := shortstring(str);
The compiler will do the work for you.
It will cut str content to fit the maximum length of st. So if st is defined as st: string[2]; if will retrieve only the 2 first characters of str.
But you may loose non ascii encoded characters in str (not a problem if it does contain only English text).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With