Jump to content

Cristian Peța

Members
  • Content Count

    338
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by Cristian Peța


  1. 23 hours ago, John Kouraklis said:

    @David Heffernan I've got that but how do I get the country code in all platforms?

    I've made it some years ago. Not the best solution but it works for what I need. And not Linux.

     

    function GetOSLangID: String;
    {$IFDEF MACOS}
    var
      Languages: NSArray;
    begin
      Languages := TNSLocale.OCClass.preferredLanguages;
      Result := String(TNSString.Wrap(Languages.objectAtIndex(0)).UTF8String);
      Result := UpperCase(Result.Substring(0, 2));//only first two chars
    end;
    {$ENDIF}
    {$IFDEF ANDROID}
    var
      LocServ: IFMXLocaleService;
    begin
      if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LocServ)) then
        Result := LocServ.GetCurrentLangID else
        Result := 'EN';
      Result := UpperCase(Result.Substring(0, 2));//only first two chars
    end;
    {$ENDIF}
    {$IFDEF MSWINDOWS}
    var
      buffer: MarshaledString;
      UserLCID: LCID;
      BufLen: Integer;
    begin
      // defaults
      UserLCID := GetUserDefaultLCID;
      BufLen := GetLocaleInfo(UserLCID, LOCALE_SISO639LANGNAME, nil, 0);
      buffer := StrAlloc(BufLen);
      if GetLocaleInfo(UserLCID, LOCALE_SISO639LANGNAME, buffer, BufLen) <> 0 then
        Result := buffer
      else
        Result := 'EN';
      StrDispose(buffer);
      Result := UpperCase(Result.Substring(0, 2));//only first two chars
    end;
    {$ENDIF}

     


  2. On 3/7/2019 at 10:39 AM, Lars Fosdal said:

    It really annoys me that they didn't adapt Error Insight for inline declared variables. So ugly!

    I can live with Error Insight garbage but when I tried inline variables in a 300k LOC project I removed them immediately because Ctrl-Click stopped working.


  3. 13 hours ago, FredS said:
    
      { TStringHelper.LastIndexOf returns wrong values } 
      //    0                 19                 38                  0-based
      s := 'Hello how are you, Hello how are you, Hello how are you';
      Assert(s.IndexOf('Hello', 38) = s.LastIndexOf('Hello', 38));

     

    Wrong test case.

    s.LastIndexOf('Hello', 38) will search starting from 38 to the left. That means in this string 'Hello how are you, Hello how are you, H'.

    First occurrences is at 19 so it "Works As Expected".

    I know this is not as other implementations but you must specify this in report if you want a change.

    And this change can brake old code so it must be strongly justified.

    • Like 3

  4. 13 hours ago, FredS said:

    Essentially all system wide methods are run through DUnitX now.
    This is how I know that RSP-15040 is still in Rio 10.3.1, I use that when anyone asks why I built my own string helper.

    You haven't told what exactly is wrong and for me is working as expected.

    Sincerely I don't have an hour to lose to identify what's wrong. Specifically what should be expected?

    There is only one "Huh?" at "s.LastDelimiter('Hello')" but it returns 53 that is good. What's wrong?

     

    P.S. The truth is that Delphi's LastIndexOf is not documented and is working but not as implemented in other languages.


  5. Actually I changed my code some years ago and now I'm painting on a bitmap scaled with Canvas.Scale (an UI Canvas) and then use Canvas.DrawBitmap() to draw UI.

    • Like 1

  6. If you meant using TCanvas, this was possible at least when mobile compilers rolled out.

    The way to do this changed a little over time but now you need to apply a transformation matrix to the canvas to reverse scaling and all you paint using canvas will match 1:1.

    There was needed also a translation of (-0.5, -0.5) in that matrix because you needed to use (0.5, 0.5) to use only one pixel. I don't know if this is the case also now. 

×