Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How fix warning compiler about string #24

Open
baxing opened this issue Mar 11, 2024 · 5 comments
Open

How fix warning compiler about string #24

baxing opened this issue Mar 11, 2024 · 5 comments

Comments

@baxing
Copy link

baxing commented Mar 11, 2024

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

@hydrobyte
Copy link
Owner

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.

@baxing
Copy link
Author

baxing commented Mar 12, 2024

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?

@hydrobyte
Copy link
Owner

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;

@baxing
Copy link
Author

baxing commented Mar 12, 2024

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.

@hydrobyte
Copy link
Owner

hydrobyte commented Mar 12, 2024

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:
ezequieljuliano/SQLBuilder4Delphi#3

Also, I'll prepare a Delphi 11 CE installation to check these warnings locally.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants