Jump to content

Anders Melander

Members
  • Content Count

    2848
  • Joined

  • Last visited

  • Days Won

    155

Posts posted by Anders Melander


  1. Just now, dmitrybv said:

    1. RTLVersion and RAD Studio Edition (Professional, Enterprise, Community Edition) are different concepts. 
    2. RTLVersion for RAD Studio 12.3 cannot be called from an external program.

    Oh - You meant what version of RAD Studio is installed on the local system.

     

    I think the InstalledUpdates registry key is the closest you can get. There's no guarantee that it's valid though since it's only informational.


  2. 4 minutes ago, Renate Schaaf said:

    help says that this version of Format isn't threadsafe

    "Not thread-safe" in this case doesn't mean crash and burn. It just means that if one thread modifies the global FormatSettings then it will affect all other threads also using it.

    Hardly a problem - even if you did output floating point values in the exception message.

    • Like 1
    • Thanks 1

  3. Just now, Kas Ob. said:

    Does the following work ?!

    
    Procedure Test;
    var
      Strings: TArray<string>;
    begin
      strings[5] := 'Hi';
    end;

    Because it is used there similar to this.

    🙂

    No, of course that doesn't work

    A dynamic array is initialized to an empty array so there needs to be a SetLength first.


  4. FWIW & FYI:

     

    54 minutes ago, Kas Ob. said:

    IntToHex Must have second parameter

    Newer versions of Delphi have IntToHex overloads for NativeInt to match the size of a pointer. I think it got introduced in Delphi 10.

     

    52 minutes ago, Kas Ob. said:

    removed TArray<string> , this one is very strange, causing access violation as the array is not initialized, the AV appear in the caller as it cause corrupt stack, or may be i am living under a rock and modern Delphi compiler do initialize it.

    TArray<T>, being a dynamic array, is a manages type and string too, so TArray<string> should be initialized automatically. Probably a compiler bug.


  5. 1 hour ago, Renate Schaaf said:

    I hate the format-strings, because I can never remember the code for the place-holders.

    If only there was some magic key you could press in the editor to display help about various relevant topics... 🙂 

    I only ever use %s %d, %n and %x - and I use those a lot so that helps but I sometime need to consult that magic key when it comes to the precision or index specifiers.

    • Like 1

  6. 1 hour ago, Kas Ob. said:

    1) Ditch "goto Done;" and use try..finally it is safer and here there is no need for goto and loop is not complex, it is just exit.

    There's not even a need for try..finally since there no resources to protect; Get rid of hr, assign the results to Result directly and just exit.

     

    Also, instead of:

    raise Exception.Create('Fail in call nr. ' + IntToStr(Count) + ' of ' +
      ProcName + ' with result $' + IntToHex(hr));

    I would use:

    raise Exception.CreateFmt('Fail in call no. %d of %s with result %x', [Count, ProcName, hr]);

    for readability.


  7. I'm working on a project like that; New units are named consistently after strict rules so we can easily locate the relevant unit. Old units are named after whatever the developer had time to type (and apparently he was always in a rush).

    So I introduced a "magic" key that when pressed at run-time displays the name of the active form/frame. It's basically just a TApplicationEvents.OnShortCut on the main form:

    image.png.f8eb74a688f285ecd3395df96b026314.png

     

    procedure TFormAnynymizedToProtectTheGuilty.ApplicationEventsShortCut(var Message: TWMKey; var Handled: Boolean);
    begin
    {$ifdef DEBUG}
      if (Menus.ShortCutFromMessage(Message) = ShortCut(VK_F1, [ssAlt])) then
      begin
        if (Screen.ActiveCustomForm <> nil) then
        begin
          var Msg := '';
          // Find frames in the form
          var Control := Screen.ActiveControl;
          while (Control <> nil) and (Control <> Screen.ActiveCustomForm) do
          begin
            if (Control is TFrame) then
              Msg := Msg + Format('Embedded frame: %s in %s.pas', [Control.ClassName, Control.UnitName]) + #13
            else
            if (Control is TForm) then
              Msg := Msg + Format('Embedded form: %s in %s.pas', [Control.ClassName, Control.UnitName]) + #13;
            Control := Control.Parent;
          end;
          Msg := Msg + Format('Active form: %s in %s.pas', [Screen.ActiveCustomForm.ClassName, Screen.ActiveCustomForm.UnitName]);
    
          TaskMessageDlg('YOU ARE IN A MAZE OF TWISTY LITTLE PASSAGES, ALL ALIKE.', Msg, mtInformation, [mbOK], 0);
        end;
    
        Handled := True;
      end;
    {$endif DEBUG}
    end;

     

    • Like 2
    • Haha 1

  8. I would argue that the type of Epsilon depends on the use case; For one an absolute explicit Epsilon is suitable (SameValue(Value, Epsilon)), for another an absolute implicit Epsilon will make sense (SameValue(Value) but with some better defaults), and for yet another a relative magnitude Epsilon would be desirable (let's call it KasObSameValue(Value, Epsilon) since we don't have it in the RTL).

     

    FWIW, the same discussion could be had about IsZero. I mostly use it to avoid division by zero and overflow errors caused by division by a very small number. I'm not really comfortable doing it but the alternative is the gazillion sporadic exceptions we had in the old application I'm working on, before we began using it.


  9. 33 minutes ago, Kas Ob. said:

    The right way ...

    I think you are missing my point.

    I'm saying that SameValue, with Epsilon specified, is documented to work in the way it does now. If it didn't then that would be a bug.

     

    You can argue that it would be better if it worked in another way (e.g. Epsilon relative to the magnitude of value) but that is not how it is documented to work, it is also subjective, and it depends on how one intends to use it.

    It's like arguing that the right way to index strings is zero based.


  10. 5 minutes ago, Kas Ob. said:

    the formula for the comparison should be

    Should? As far as I can tell the current implementation matches the documented behavior. Yours doesn't.

    You might prefer another behavior, which is perfectly reasonable, but it doesn't make the current one wrong.

     

    I agree that SameValue without the Epsilon parameter is at best problematic but, with regard to the choice of default Epsilon, we don't know what the criteria was for the values they chose (because it isn't documented) so I can't see how we can say that they are wrong. Again; We might prefer other values but that doesn't make the current values wrong.


  11. As far as I can tell they've been forced to replace their proprietary APIs with standard APIs (in order to avoid vendor lock-in) and to allow competing third party applications access to their map data. Did I understand that right?

     

    It seems Google has few friends in the map business; They aren't allowed to link to Google Maps from their Google search results - or even from the search page (which is pretty stupid and doesn't do the users any good), while the same restrictions doesn't apply to Bing. Could it be that Bing map data is provided by Tom-Tom?

    • Like 2

  12.  

    5 hours ago, bk31415 said:

    I am writing an (MQTT) broker (serves) that serves about 100 clients.

    9 minutes ago, bk31415 said:

    Both machines (A and B) single-user, they will access one another over the local network --not from Internet or similar.

    Alright then.

     

    So you are going to violate the license and don't want that aspect discussed. That's between you, Microsoft, and whatever unfortunate user/client, if any, this involves but maybe you shouldn't ask us to help you do it.


  13. 2 minutes ago, bk31415 said:

    This must be the strictest possible interpretation out there.

    No it's not; You are not allowed to use a desktop Windows as a server. What other people that violate the license say about that isn't really relevant.

     

    Quote

    Installation and Use Rights.

    Restrictions.

    For the avoidance of doubt, this license does not give you any right to, and you may
    not (and you may not permit any other person or entity to):

    ...

    use the software as server software or to operate the device as a server, except as permitted under Section 2(d)(iii) below; use the software to offer commercial hosting services; make the software available for simultaneous use by more than one user over a network, except as permitted under Section 2(d)(vi) below;
    install the software on a server for remote access or use over a network; or install the software on a device for use only by remote users;

     

×