McJSON
McJSON copied to clipboard
How fix warning compiler about string
Hello,
I gave the variable a JSON string value before adding the value to the JSON object with the AsJSON method, which caused a warning. TestMcJSON_.zip [This if sample project] But I get 33 warning messages after compilation. about :
- W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit
- W1057 Implicit string cast from 'AnsiString' to 'string'
- W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'
Plese advice me to fix these
Thank you
Hi,
I think you are using a newer version of Delphi, so this might be expected as string maps to UnicodeString.
Into your code, try to use AnsiString type instead of string when passing content to AsJSON method.
I use Delphi 10.3
only this code give 33 warning together
jSon := TMcJsonItem.Create;
jSon.AsJSON := '{"key1":1,"key2":true,"key3":1.234,"key4":"value 1","array":[1,2,3]}';
MMO1.Text := jSon.ToString(True);
jSon.Free;
Could you please give an example? If I use the code as in the example, where will I have to adjust it?
Try change lContent type:
procedure TForm1.btn1Click(Sender: TObject);
var
jSon: TMcJsonItem;
lContent: AnsiString;
begin
jSon := TMcJsonItem.Create();
lContent := '{"key1":1,"key2":true,"key3":1.234,"key4":"value 1","array":[1,2,3]}';
jSon.AsJSON := lContent;
try
MMO1.Text := jSon.ToString(True);
finally
jSon.Free;
end;
end;
It still gives 33 warnings message follow :
[dcc32 Warning] McJSON.pas(179): W1010 Method 'ToString' hides virtual method of base type 'TObject' [dcc32 Warning] McJSON.pas(180): W1010 Method 'ToString' hides virtual method of base type 'TObject' [dcc32 Warning] McJSON.pas(238): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(239): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(240): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(241): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(242): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(243): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(244): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(245): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(282): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(291): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(292): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(293): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(294): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(312): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(344): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1012): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1081): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1083): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1089): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1097): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1098): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1114): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1402): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1405): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1736): W1057 Implicit string cast from 'AnsiString' to 'string' [dcc32 Warning] McJSON.pas(1744): W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString' [dcc32 Warning] McJSON.pas(1747): W1057 Implicit string cast from 'AnsiString' to 'string' [dcc32 Warning] McJSON.pas(1952): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1952): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1953): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. [dcc32 Warning] McJSON.pas(1953): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit.
I'll study how to solve this W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit. thing.
I think I must use AnsiString instead string internally.
It is related to: https://github.com/ezequieljuliano/SQLBuilder4Delphi/issues/3
Also, I'll prepare a Delphi 11 CE installation to check these warnings locally.
Thanks.
Hi, Fixed in last commit. Sorry for the delay.