Same project Win8.1 vs. Win10. Encoding differences? lazarus / 34-Windows ---------------------------------------------------------------------- Eduards · 2019-04-20 13:14 Hello, I have problem with different windows/lazarus versions and same project synced using dropbox. My project uses Indy 10 to read and write Google Calendars using functions originaly written for Delphi. Maybe I should note that unit has warnings like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i googlecal.pas(521,35) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"googlecal.pas(522,19) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"but they which were not causing any problems. Step 1. I had my project build some time ago in Lazarus 1.6.2 / win 8.1 pro. It was working. Step 2. I installed on laptop Lazarus 1.6.4 / win 10 Home. Project is synced from machine to machine using dropbox, I just rebuilt it, it was working on laptop no problem. If I run this new executable on original desktop machine, my project asks for new google token to access Google Calendars. When I enter one, it does not accept it. Token is saved to file on every exit. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     Line := TStringList.Create;  Line.Add(GCalendars.RefreshToken);  Line.SaveToFile('data/google-token.ini');Same executable asks for no tokens on laptop and just works. So I upgraded to Lazarus 2.0 on my desktop windows 8.1 machine.  After compiling Indy twice (nothing changed there) I could build my project. Same thing continues- program asks for token, while on Win 10 laptop it works no questions asked. I have no idea if problem is system code pages, Lazarus UFT8, line endings or I what else. I will include whole GetTokens procedure in case that helps. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TGCalendars.GetTokens;  function EncodeURL(url: string): string;  var    x: integer;    sBuff: string;  const    SafeMask = ['A'..'Z', '0'..'9', 'a'..'z', '*', '@', '.', '_', '-'];  begin    //Init    sBuff := '';     for x := 1 to Length(url) do    begin      //Check if we have a safe char      if url[x] in SafeMask then      begin        //Append all other chars        sBuff := sBuff + url[x];      end    else if url[x] = ' ' then      begin        //Append space        sBuff := sBuff + '+';      end      else      begin        //Convert to hex        sBuff := sBuff + '%' + IntToHex(Ord(url[x]), 2);      end;    end;     Result := sBuff;  end; var  URLString: String;  OkResult: Boolean;  InputResult: string;  JSon: ISuperObject;  FCode: String;  Req, Resp: TStringStream;begin  FAccessToken := '';  if FRefreshToken <> '' then  begin    { Lets get access token using previous refresh token}    URLString := 'client_id=' + FClientID;    URLString := URLString + '&client_secret=' + FClientSecret;    URLString := URLString + '&refresh_token=' + FRefreshToken;    URLString := URLString + '&grant_type=refresh_token';    Req := TStringStream.Create(URLString);    Resp := TStringStream.Create('');    try      try        FHTTP.Request.ContentType := 'application/x-www- form-urlencoded';        FHTTP.DoRequest('POST', 'https://accounts.google.com/o/oauth2/token', Req, Resp, []);        { When not working response was:        Recv 31.12.2017. 14:12:59: HTTP/1.1 400 Bad Request          "error" : "invalid_grant" }       except      end;      if FHTTP.ResponseCode = 200 then      begin      JSon := SO(UTF8Decode(Resp.DataString));        FAccessToken := JSon['access_token'].AsString;        if JSon['refresh_token'] <> nil then          FRefreshToken := JSon['refresh_token'].AsString;        Exit;      end;    finally      Req.Free;      Resp.Free;    end;  end;   { Ja kods augstāk bijis veiksmīgs, tas iziet ar Exit, un šis tālāk neizpildās.    Šeit tiek apstrādāts, ja refresh_token ir neveiksmīgs. Atveram browseri lai iegūtu "user consent" }   URLString := 'https://accounts.google.com/o/oauth2/auth';  URLString := URLString + '?client_id=' + FClientID;  URLString := URLString + '&redirect_uri=urn:ietf:wg:oauth:2.0:oob';  URLString := URLString + '&scope=https://www.googleapis.com/auth/calendar https://www.google.com/m8/feeds';  URLString := URLString + '&response_type=code';  OpenURL(UrlString); { Lazarus equivalent of Delphi ShellExecute((Form.Handle), nil, PChar(URLString), nil, nil, 0); }   repeat    OkResult := false;    InputResult := '';    if Assigned(FOnAuthorizationContinueQuery) then      FOnAuthorizationContinueQuery(Self, OkResult, InputResult)    else    OkResult := InputQuery(Application.Title, 'Enter your code here:', InputResult);    if OkResult then      FCode := InputResult  { that code I copy/pasted from browser }    else      Exit;     URLString := 'client_id=' + FClientID;    URLString := URLString + '&client_secret=' + FClientSecret;    URLString := URLString + '&code=' + FCode;    URLString := URLString + '&redirect_uri=urn:ietf:wg:oauth:2.0:oob';    URLString := URLString + '&grant_type=authorization_code';    Req := TStringStream.Create(URLString);    Resp := TStringStream.Create('');    try      try        FHTTP.Request.ContentType := 'application/x-www- form-urlencoded';        FHTTP.DoRequest('POST', 'https://accounts.google.com/o/oauth2/token', Req, Resp, []);        except      end;      if FHTTP.ResponseCode <> 200 then      begin      if Assigned(FOnWrongVerifier) then          FOnWrongVerifier(Self)        else          MessageDlg('Wrong code! Try again.', mtError, [mbOK], -1);      end      else      begin        { iegūstam gan access_token, gan refresh_token }        JSon := SO(UTF8Decode(Resp.DataString));        FAccessToken := JSon['access_token'].AsString;        if JSon['refresh_token'] <> nil then          FRefreshToken := JSon['refresh_token'].AsString;      end;    finally      Req.Free;      Resp.Free;    end;  until FHTTP.ResponseCode = 200;end; ---------------------------------------------------------------------- JimD · 2019-05-21 19:10 Can we see the code snippet that is causing the warnings? googlecal.pas(521,35) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString" googlecal.pas(522,19) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString" ---------------------------------------------------------------------- Eduards · 2019-07-01 14:26 Here is the code. I have never worked with JSON, I use these functions and they "just work". Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TGEvent.SetJSON(const Value: WideString);   var  JSONDoc: ISuperObject; begin  if FJSON <> Value then  begin    FStored := True;    FJSON := Value;    JSONDoc := SO(UTF8Decode(Value));   // Line 521    FID := JSONDoc['id'].AsString;      // Line 522    FETag := JSONDoc['etag'].AsString;    FTitle := '';  Update. Since my original post I have upgraded all my machines to Win10. No changes. Code compiles everywhere fine, but runtime version works as intended only on initial laptop.