Jump to content

Anders Melander

Members
  • Content Count

    2854
  • Joined

  • Last visited

  • Days Won

    156

Posts posted by Anders Melander


  1. https://en.delphipraxis.net/search/?&q=profilers&search_and_or=or&sortby=relevancy

    https://www.google.com/search?q=delphi+profiling

     

    1 hour ago, Charlie Heaps said:

    I'm a bit surprised Embarcadero has never integrated this capability into a version of the Delphi IDE.  It's a vital kind of tool for programming.

    A few versions (around XE) had a limited version of AQTime bundled in.
    Apart from that it's hardly their area of expertise and it's been ages since they had resources to spare for anything but the core product.

     

    1 hour ago, Charlie Heaps said:

    It would great if this community would consider pleading with the AQTime authors (SmartBear) to open source AQTime.  (I'm probably being naive!)

    That will never happen. There's simply no benefit for them in open sourcing it, only expense, and it probably also contains code that can't be open sourced.


  2. 1 hour ago, araujoarthur said:

    I would totally jump into TdxCalloutPopup if I knew a way to totally disable DX Skins from intefering/side effects.

    It took me a good while to spot the difference between the two screenshots but I get your meaning.

    AFAIK it's possible to control DevExpress' skinning of standard VCL controls to some degree. See TdxSkinController.OnSkinControl

     

    7 minutes ago, pyscripter said:

    The library also supports controls on menus and toolbars and is Vcl styles compliant.

    The dependencies though 😕


  3. The easiest way is probably to just use a TForm as the poup.

     

    You need to:

    • Display the form with ShowWindow(SW_SHOWNA).
    • Handle WM_NCACTIVATE to avoid the form activating when clicked.
    • In CreateParams:
      • Set Params.WndParent to the parent form.
      • Add WS_POPUP and WS_CLIPCHILDREN to Params.Style and exclude WS_CHILD.
      • Add WS_EX_TOPMOST and WS_EX_TOOLWINDOW to Params.ExStyle. If you will be implementing the form shape with alpha blending then you also need to add WS_EX_LAYERED.
    • Shape the form either with alpha blending (WS_EX_LAYERED and SetLayeredWindowAttributes) or with regions (I can't remember the APIs for that OTOH).

    I'm sure that if you search github for the above (with lang:pascal) that you can find some Delphi examples.

    See also: http://melander.dk/articles/alphasplash/

     

    ...or you could just throw some $$$ at DevExpress and use their TdxCalloutPopup control:
    image.thumb.png.9ce2ca5eaa0dedade414fc70566b769f.png

    • Thanks 1

  4. 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.


  5. 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

  6. 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.


  7. 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.


  8. 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

  9. 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.


  10. 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

  11. 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.


  12. 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.


  13. 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.

×