Jump to content

pyscripter

Members
  • Content Count

    785
  • Joined

  • Last visited

  • Days Won

    42

Posts posted by pyscripter


  1. Please file appropriate bug reports and open PRs,

     

    On note regarding WrapDelphi:

    The WrapDelphiXYZ units were written before the enhanced RTTI was implemented.  Nowadays you do not need to wrap enumerations sets and the like.  Here is an example from WrapDelphi unit tests:


     

    type
      TFruit = (Apple, Banana, Orange);
      TFruits = set of TFruit;
    
      TTestRttiAccess = class
      private
        FFruit: TFruit;
        FFruits: TFruits;
      public
        FruitField :TFruit;
        FruitsField: TFruits;
        StringField: string;
        DoubleField: double;
        ObjectField: TObject;
        RecordField: TTestRecord;
        InterfaceField: ITestInterface;
        procedure BuyFruits(AFruits: TFruits);
        property Fruit: TFruit read FFruit write FFruit;
        property Fruits: TFruits read FFruits write FFruits;
      end;
    

     

    With the above declarations and if you Wrap a variable say test of type TTestRttiAccess you can write python code such as:

     

    test.Fruit = 'Apple'
    test.Fruits = ['Apple', 'Banana']

     

     

    So there is no need to create special wrappers of enumerations and sets.

     

    The WrapDelphi unit tests are worth studying in some depth.

     


  2. I guess everyone knows this already, but I did find this Stackoverflow answer surprising.  Can you guess what is the message shown?

    function DoSomething(SomeBoolean: Boolean) : string;
    begin
        if SomeBoolean then
            Result := 'abc'
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
        xx: string;
    begin
        xx := DoSomething(True);
        xx := DoSomething(False);
            ShowMessage(xx);
    end;

    Shouldn't the above deserve a compiler warning?


  3. 15 minutes ago, NamoRamana said:

    Ok, Guys.. took me a while to come up with reproducible code.. But its attached here. You will see that with each click on a button, the memory increases. We also ran the same code under D 10.4.1 and unfortunately, the behavior is the same -- it keeps on increasing the memory.

     

    COMBug.zip

     

    function TObjSvr.ObjAddRef: Integer;
    begin
      OutputDebugString(PChar(Format('TObjSvr ($%08X) AddRef', [integer(Self)])));
    end;
    
    function TObjSvr.ObjRelease: Integer;
    begin
      OutputDebugString(PChar(Format('TObjSvr ($%08X) Release', [integer(Self)])));
    end;

    Υour are overriding ObjAddRef, ObjRelease, without calling the inherited method. and you expect to see no memory leaks?

    • Haha 1

  4. The first VCS I used a long-time ago were CVS and FreeVCS (anyone remembers that?). 

    In the days of Google code, I became an SVN fan using TortoiseSVN.   When Google Code shut down all projects moved to Github and converted to git.  But, I was very reluctant to move to git  and carried on using SVN to work with Git repositories.  Soon, I realize this change-resisting approach was counter-productive.  I then switched to TortoiseGit and never looked back. 

     

    Having to fork a repository to submit a PR is rather cumbersome (I wish you could do that from a clone), but I do understand the reasons why this is so.


  5. One of the new features of Delphi 10.4 was the new TEdgeBrowser component.  It is nice.  However the downside is that certain steps are needed for the use and delployment of this component:

    1.  Install Edge WebView2 package via GetIt.  This places a Dll called WebView2Loader.dll in the redist directory of Embarcadero studio (one for win32, one for win64).
    2. The appropriate WebView2Loader.dll needs to be deployed alongside your executable. (about 300Kb).  While developing you can add a post-build event to do that.
    3. Now the difficult one was that you had to replace the stable version of Edge, installed and managed by Windows, with the unstable one from the Canary Edge update channel (daily updates).  Event if you did that in your own machine, few users would accept it.

     

    The new thing, that is not mentioned in the documentation, is that there is a better alternative to the third requirement.   You can use the WebView2 Runtime installer which works independently from and does not interfere with your browser, and can be safely deployed in customer sites.   Give it a try.

     

     

    • Like 2

  6. This is another tough one to work around:

     

    procedure TCustomForm.ScaleForPPIRect(NewPPI: Integer; NewRect: PRect);
    var
      LCurrentPixelsPerInch: Integer;
      I: Integer;
      PriorHeight: Integer;
    begin
      if not (csDesigning in ComponentState) and
        ((not HandleAllocated and (Parent <> nil)) or (NewPPI < 30)) then
        Exit;

    Parented forms with  unallocated handle are not scaled (e.g. page-like controls).  It becomes even harder since TCustomForm.SetParent destroys the handle if the form had no parent.

    This is irrespective of FreeNotifications.


  7. @Uwe Raabe Thanks!  Good to know I am not the only one bitten by this (should have checked QA),  but bad to know it has not been fixed for quite some time now.  I placed my vote on the first issue.

     

    You can work around the bug by manually calling ScaleForPPI(future parent PPI)  before setting the parent but it gets difficult to get right with things like docking.   Embarcadero will face this issue when they try to make the IDE per monitor DPI-aware as promised.    


  8. TControl.SetParent contains the following code:

     

          if not (csLoading in ComponentState) and not (csDesigning in ComponentState)
            and not (csDestroying in ComponentState) and not (csFreeNotification in ComponentState) then
          begin
            if not (csDesigning in Parent.ComponentState) then
              ScaleForPPI(GetParentCurrentDpi);
          end;

    Apart from the fact that I would write the if condition as

          if [csLoading, csDesigning, csDestroying, csFreeNotification] * ComponentState = [] then

    does anyone have any idea why controls with csFreeNotification are not scaled?   This makes writing per Monitor DPI aware applications much harder.


  9. 36 minutes ago, Anders Melander said:

    Remember that we're talking about UCS4StringToWideString and not WideStringToUCS4String

    The issue is the in-memory representation of USC4.  Should it have the redundant (obviously, no need to make the same argument multiple times :classic_smile:) #0 or not?   And I argued that for inter-operability (passing a pointer to external functions expecting  null-terminated UCS4) it is better that it always includes it despite the redundancy.   And this is what the RTL assumes and does.


  10. 3 hours ago, A.M. Hoornweg said:

    Most programmers ignore that UTF-16 is a variable-length encoding and treat it like UCS-2, falsely assuming that one widechar corresponds to one codepoint.  While most of us probably don't handle exotic languages, this is the 21st century and sooner or later you'll stumble upon strings that contain Emoticons which just won't fit in one widechar ( https://en.wikipedia.org/wiki/Emoticons_(Unicode_block) .

    You don't have to use USC4 for that and using USC4 would not solve this problem.  There are mainly two issues:

     

    1) Surrogates pairs (two widechars correspond to one glyph)  UCS4 would help with this one.
    UTF-16 Encoding: 0xD83D 0xDCBC 

     

    2) Combining characters (more than one Widechars shown as one glyph).  But UCS4 would not help with this one.
    Åström ḱṷṓn
    Precomposed vrs Decomposed
    ḱṷṓn (U+1E31 U+1E77 U+1E53 U+006E)
    ḱṷṓn (U+006B U+0301 U+0075 U+032D U+006F U+0304 U+0301 U+006E)

     

    Windows provides CharNext/Prev that deals with both issues,  but not perfectly.  You have to use Uniscribe or DirectWrite for greater accuracy.

     

    In SynEdit there is this function:

    function SynCharNext(P: PWideCharout Element : String) WideCharoverload;
    Var
      Start : PWideChar;
    begin
      Start := P;
      Result := Windows.CharNext(P);
      SetString(Element, Start, Result - Start);
    end;

     

     

    It is very easy to write an enumerator that works with CharNext.

     


  11. 1 hour ago, Anders Melander said:

    I meant the function doesn't need it to be zero terminated (it has the length already).

    Why should any Delphi program use UCS4?  The main use case is for inter-operability.   You would need to pass the result to some external function.   Having to manually add the null-terminator, would be inconvenient.


  12. 7 hours ago, Marco Cantu said:

    Honestly, I don't see us putting a lot of effort in UCS4String

    I suppose this is understandable.   The Windows world is on UTF-16 and the rest on UTF-8.  UCS4 (UTF-32) is very rarely used.

     

    With the benefit of hindsight, UTF-8 would probably have been a better choice for Windows.  Now Microsoft is trying to bring UTF-8 back into Windows via the A routines and by offering to make UTF-8 the default character encoding.


  13. @Uwe Raabe One issue I had recently was with the IDE crashing badly when going View Form as Text and then back.  I disabled Project Magician and the issue went away.

    Using Delphi 10.4.1 and the latest version of Project Magician.

    Delphi Magician options:

     

     image.thumb.png.0a754598f1b2746acd4fac4b9050e299.png 

     

    The crash also occurred with a fresh VCL application and an empty Form.


  14. @dummzeuchAll these limitations of LockWindowUpdate are well known and noted.   Yes you should avoid using LockWindowUpdate if you can and prefer WM_SETREDRAW.  Fully agree.  WM_SETREDRAW was the first thing I tried and did not work.

     

    As Raymond Chen says in the above articles

    Quote

    By now, you’ve probably noticed a common thread to all of these LockWindowUpdate scenarios: They all involve dragging of some sort. Dragging a window caption to move it, dragging the edge of a window to resize it, dragging an item into a window, or dragging an item out of a window. This is not a coincidence. The LockWindowUpdate function was designed with these drag scenarios in mind. Since dragging an item uses the mouse button, and there’s only one mouse, you can’t have multiple drag operations in progress at once, and therefore, there’s no need to lock more than one window for update at a time. The function should perhaps more accurately have been named LockDragWindow.

    One can well argue therefore, that dragging a Window from one monitor to another is a valid case for using LockWindowUpdate. If it is OK to lock the whole desktop when you do OLE drag&drop it should be OK to lock a single window while dragging it between monitors, just for the time it rescales.

     

    • Like 4
×