Jump to content

pyscripter

Members
  • Content Count

    1020
  • Joined

  • Last visited

  • Days Won

    66

Posts posted by pyscripter


  1. Inheritance Tree:

    IEnumerable<T>

      IReadOnlyCollection<T>

       ICollection<T>

         ISet<T> 

     

      IEnumerable<T> has many functions including Contains:

        function Contains(const value: T): Boolean; overload;
        function Contains(const value: T; const comparer: IEqualityComparer<T>): Boolean; overload;
        function Contains(const value: T; const comparer: TEqualityComparison<T>): Boolean; overload;

     

    • Thanks 1

  2. You probably have noticed that when you press the middle mouse button in the Delphi IDE the editor goes into panning mode, that allows you to scroll by moving the mouse.   Many of the Vcl.Controls are panning enabled including the Memos, Grids, ContolLists, TabControls, Treeviews and others.   For a complete list just search for csPannable in the Delphi Vcl source code folder.   They use the exact same code that the IDE uses and behave in exactly the same way.  However, what you may not know (I did not), is that to enable panning you need to include in your project the Vcl.IMouse unit.  Vcl also makes it easy to add panning to your custom controls.  All it takes is to add the csPannable control style.  So SynEdit now has the same panning support as the Delphi IDE.

     

    However, I have discovered two bugs related to Vcl panning:

     

    Both are easy to fix, so hopefully Embarcadero will provide fixes soon enough!  In the meantime, it is easy to work around the memory leak and hopefully live with the second one, which also affects the Delphi IDE.

    • Like 1
    • Thanks 4

  3. 3 hours ago, dummzeuch said:

    As for parallel connections:

    The unmodified LocalForward demo works for two different browsers in parallel. But after closing the second browser I get ESshError "LibSSh2 error: Unable to send channel-open request (-7), on API "libssh2_channeld_direct_tcpip_ex" in SshTunnel, line 170. This then happens every time I try to connect to http://localhost:12345/success.txt So there still seems to be something amiss.

    I committed a change trying to fix this.  Could you please try once more.


  4. 8 hours ago, shineworld said:

    it seems to me that each new module requires a PyEngine which loads the python DLL and this is already instantiated by DelphiVCL

    This is not correct.  When P4D is used in an extension module it uses LoadDllInExtensionModule which just uses the dll loaded in the python process.  It does not load or initialize the python dll.  The calling process does that.  So you can have more than one Delphi generated pyd files without issues.

    • Thanks 1

  5. @dummzeuch Please see my latest commit.  TSshTunnel.ForwardLocalPort has been refactored and can now handle multiple connections sequentially.  So your use case may be working.  Could you please test.  

     

    I will also see whether the connections can be handled in parallel.  Is there a use case for that?  Can you have multiple connections simultaneously on the same port? 

    • Like 1

  6. @dummzeuchI have updated the build scripts and the binaries which do not need OpenSSL.

     

    Could you please try the new binaries and see whether you still get the error you mentioned?  These binaries work well with ssh-agent password-less authentication, whilst the Php ones don't.

     

    Also would it be possible to post a test project that requires multiple connections, so that I can have a go at fixing the issue?


  7. 1 hour ago, dummzeuch said:

    but I have been doing something wrong

    Probably not.  When you add commits to the same branch, the commits are added to the PR.  If you want to have separate PRs you need different branches for each change. Anyway your changes have been merged and you are listed as a contributor.


  8. @dummzeuch  I think handling connections sequentially should be quite easy, without resorting to multiple threads.  Once one is closed you wait for the next one. 

    Please bear in mind, that there are limitations when using libssh2 from multiple threads:

     

    Quote

     

    Using libssh2 in a multithreaded application requires some caution. While libssh2 itself can be used in a multithreaded environment, there are important limitations to be aware of:

    1. Initialization: You need to ensure that libssh2_init() is called in a thread-safe manner. This means it should be called before any threads are created that will use libssh21.

    2. Session Handling: You cannot use a single session (or channels for a single session) across multiple threads simultaneously. Doing so can lead to internal state corruption2. Each thread should have its own session if they need to perform SSH operations concurrently.

    3. Thread Safety: The underlying cryptographic libraries (like OpenSSL or GnuTLS) need to be initialized in a thread-safe manner. This often involves setting up mutexes for the cryptographic operations1.

    If you follow these guidelines, you should be able to use libssh2 in a multithreaded application without running into major issues. Do you have a specific use case or problem you’re encountering with libssh2?

     

     

    Points 1 and 3 are the same, since the crypto functions are initialized by libssh2_init.   Ssh_pascal handles this in a thread safe manner.  The second point, I think means that you either have a session per thread or you protect with a lock, access to the same session and its channels,
     
    • Like 1

  9. 2 hours ago, John R. said:

    Fantastic work! Thank you for your contributions.

    If I may, while this component is very powerful, I find that a serious limitation is the number of languages that it supports and the difficulty to add new languages. Many common languages are missing (such as Powershell, Rust, TypeScript, Go...) and creating highlighters is complicated.

    @pyscripter as you know the internals better than anyone, would it be possible to imagine a way to import highlighters from other projects such as highlight.js: https://github.com/highlightjs/highlight.js/blob/main/src/languages/powershell.js ?

    Or would it be better to imagine a simpler way to define highlighters ?

    There are about 75 highlighters and It is not too difficult to add new ones.

    • You can start with a highlighter for a language that is quite similar and adapt it, e.g. change the keywords.
    • There is also SynGen that helps you create a highlighter from scratch.
    • You can request a highlighter and someone may have or contribute  a new one.

     

    Regarding Powershell have a look at this discussion.  It contains an extended General highlighter that can be adapted to practically any language.   PSPad uses that unit to support syntax highlighting for 180 programming languages. 

     

    • Like 1

  10. I have no idea what you are trying to accomplish, but for instance you can put the PythonModule in a data module.   Instead of using AddDelphiMethod directly. you could add an Event to the PythonModules Event's collection.  Events are converted to python functions,  which delegate the execution to a Delphi event handler.  Then, every time the form is created, it could assign a handler to the event's OnExecute property.  


  11. In the demo project modify the CreateEngine function as follows:

     

    procedure TService1.CreatePyEngine;
    begin
      PythonEngine := TPythonEngine.Create(nil);
      PythonEngine.Name := 'PythonEngine';
      PythonEngine.DLLName := 'python313.dll';
      PythonEngine.DllPath := 'c:\python\python313\';
      PythonEngine.PythonHome := PythonEngine.DLLPath;
      PythonEngine.VenvPythonExe := PythonEngine.DLLPath + 'python.exe'; // may be needed
      PythonEngine.RegVersion := '3.13';
      PythonEngine.UseLastKnownVersion := False;
      PythonEngine.FatalAbort := False;
      PythonEngine.FatalMsgDlg := False;
      PythonEngine.LoadDll;
      TPythonThread.Py_Begin_Allow_Threads;
    end;

     

    I think this should set the python path correctly and avoid import errors.


  12. What I think is best:

    - Create the pythonEngine (or load the python dll) on Start

    - Destroy the pythonEngine (or unload the python dll) on Stop

    - Follow these guideliines to execute python code in threads.

     

    Please see the attached project for an example that does that.

    Sample log output after  starting and stopping the engine:

     

    Logs From Background Thread: 24/10/2024 14:49:18
    Python eval = 4
    Logs From Background Thread: 24/10/2024 14:49:19
    Python eval = 4
    Logs From Background Thread: 24/10/2024 14:49:20
    Python eval = 4
    Logs From Background Thread: 24/10/2024 14:49:21
    Python eval = 4

    Service.zip


  13. SynEdit now has annotated Scrollbars.

     

    image.thumb.png.5ac90dd23cacbcc55cccdd6fc28d7c56.png

     

    In this screenshot you can see in the scrollbar:

    • the position of the multiple carets (full blueish line)
    • lines with errors (full red line)
    • the position of the bookmarks (mini bluish marks on the left)
    • line modification info (on the right side)
    • alpha-blended slider

     

    This feature is on the multicaret branch.

    Zoom In/Out/Reset functionality has also been implemented.

     

    You can still vote on this poll to influence future development.

    See the technical details.

    See also SynEdit now supports mulit-caret, multi-selection editing - I made this - Delphi-PRAXiS [en].

    • Like 3
    • Thanks 2
×