Atozed Forums

Full Version: array of wide char warning
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have this array of widechar 

Code:
  SpecialChars: array[1..60] of WideChar = (
    #0160, #0169, #0174, #8482, #0185, #0178, #0179, #0034, #0038, #0060,
    #0062, #8211, #8212, #8216, #8217, #8220, #8221, #8226, #8224, #8225,
    #8242, #8243, #8249, #8250, #0732, #0710, #9824, #9827, #9829, #9830,
    #9674, #8592, #8594, #8593, #8595, #8596, #0172, #0188, #0189, #0190,
    #0177, #0171, #0187, #0176, #0171, #0186, #0161, #0191, #8364, #0162,
    #0163, #0165, #0164, #0167, #0182, #0175, #0183, #0181, #0215, #0247);


i got this compiler warning during compilation 


Quote:[dcc32 Warning] SimpleHTML.pas(203): W1063 Widening given AnsiChar constant (#$F7) to WideChar lost information


any idea how to handle this warning ?
First, this has nothing to do with Indy, so you should not have posted this in an Indy forum.  A general Delphi forum would have been more appropriate.

Second, there is no #$F7 (or #0127) literal in the code you have showed.

However, that being said - more than half of your literal values are subject to the {$HIGHCHARUNICODE} compiler directive.  Do you have that directive set to ON or OFF?  I suspect it is OFF, which is the default:

Quote:When HIGHCHARUNICODE is OFF:

- All decimal #xxx n-digit literals are parsed as AnsiChar.
- All hexadecimal #$xx 2-digit literals are parsed as AnsiChar.
- All hexadecimal #$xxxx 4-digit literals are parsed as WideChar.

When HIGHCHARUNICODE is ON:

- All literals are parsed as WideChar.

So try turning the directive ON for your array:

Code:
{$HIGHCHARUNICODE ON}
SpecialChars: array[1..60] of WideChar = (
    #0160, #0169, #0174, #8482, #0185, #0178, #0179, #0034, #0038, #0060,
    #0062, #8211, #8212, #8216, #8217, #8220, #8221, #8226, #8224, #8225,
    #8242, #8243, #8249, #8250, #0732, #0710, #9824, #9827, #9829, #9830,
    #9674, #8592, #8594, #8593, #8595, #8596, #0172, #0188, #0189, #0190,
    #0177, #0171, #0187, #0176, #0171, #0186, #0161, #0191, #8364, #0162,
    #0163, #0165, #0164, #0167, #0182, #0175, #0183, #0181, #0215, #0247);

Alternatives are to either:

- initialize your array using type-casted integers:

Code:
SpecialChars: array[1..60] of WideChar = (
    WideChar(160), WideChar(169), ...);

- initialize your array using a Unicode string literal instead of individual character literals:

Code:
SpecialChars: array[1..60] of WideChar = ' ©®™¹²³"&<>–—‘’“”•†‡′″‹›˜ˆ♠♣♥♦◊←→↑↓↔¬¼½¾±«»°«º¡¿€¢£¥¤§¶¯·µ×÷';

- in which case, why not just change the array into a UnicodeString? (make sure to use {$ZEROBASEDSTRINGS OFF} when indexing into the string, if needed):

Code:
SpecialChars: UnicodeString = ' ©®™¹²³"&<>–—‘’“”•†‡′″‹›˜ˆ♠♣♥♦◊←→↑↓↔¬¼½¾±«»°«º¡¿€¢£¥¤§¶¯·µ×÷';