Jump to content

pyscripter

Members
  • Content Count

    782
  • Joined

  • Last visited

  • Days Won

    42

Posts posted by pyscripter


  1. 19 hours ago, Brian Evans said:

    PyScripter is opensource so you can read the code. A quick look seems to suggest it doesn't - it unloads a bunch of common .pyd that might be loaded.

    Indeed.  As I said it is not foolproof.  If you use a specific set of python modules, you can see in Delphi's debug mode which DLLs are loaded when your python scripts execute.  You can then write code to unload them after unloading python.   Failing to unload a DLL does not necessarily mean that there will be an issue next time you load python.   


  2. 8 hours ago, David Heffernan said:

    Has this changed?

    Unloading and reloading has always been possible with P4D, but quite tricky and not foolproof.  You need to manually unload the dll's loaded by imported modules and if you fail to do that it will fail.   PyScripter does that and allows you to change python version without exiting.

    • Like 1

  3. 17 hours ago, tomye said:

    as i said,  i set 

     

    TPythonThread.Py_Begin_Allow_Threads;

    Why are you making things complicated?  Follow the KISS rule.   Using threads in this way requires deep knowledge of the Python API and the complexities of GIL.

     

    If do have to use threads, please study Demo  11  and the related posts in this forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net)  


  4. 16 hours ago, tomye said:

    the anaconda which i installed is 64-bit

    PythonHome needs to be set even for registered conda distributions
     

    See TPythonVersion.AssignTo(PythonEngine: TPersistent); in PythonVersions.pas about this is done.

     

             Note also that for conda distributions to work properly,
             you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath]
             to your Windows path if it is not there already.


  5. In general, Python scripts run just as fast (or better just as slow) using P4D in Delphi, as they do using python.exe.

    7 hours ago, RDAF said:

    or the mechanism that transfers variables between Python

    and Delphi

    You need to show what you are doing in that respect.


  6. On 9/28/2022 at 10:28 PM, acaland said:

    what is the difference between P4D and Python4Lazarus?

    Python4Lazarus is a fork focusing on fpc support.  It does not include the based on WrapDelphi, delphifmx, delphivcl stuff. 


  7. 2 hours ago, BennieC said:

    @pyscripter

    I have used your structure but still Delphi insist on giving me strings instead of floating point values.

    image.png.b6cae72d144f79f4288f7f6bc2646a68.png

    Can I somehow force the variant conversion to take this as a float?  I have tried to assign the variant to single variable but have no luck.

    Regards

     

    Variants are converted to strings when shown in the debugger.  It does not mean that they contain strings.


  8. 2 hours ago, BennieC said:

    Value: (array([[0.09, 0.03, 0.34...0.]]. dtype=float32), array([[0.06, 0.05, 0.67...0.]]. dtype=float32))

    Currently this is just returned as a value with name layerOutputs, but Delphi sees this as a character string

    No it does not.   You get a tuple containing arrays of floating type values.   Are you using VarPyth? Is layerOutputs a Variant?

    If yes then you can use:

     

    var arr:Variant := layerOutputs.GetItem(0);  // the first item of the tupple (array).
    var value:Variant := arr.GetItem(0);  //the first floating value of the array

     


  9. 6 minutes ago, Vincent Parrett said:

    If that were the case, then you wouln't need to change anything at all in SynEdit - but you do as it cannot see SetAdditionalPCREOptions.

    The issue was in the following:

     

    procedure TRegExHelper.AddRawOptions(PCREOptions: Integer);
    begin
      with Self do FRegEx.SetAdditionalPCREOptions (PCREOptions);
    end;

    FRegEx is defined in System.RegularExpressions and the nearest helper was in that unit.

     

    By the way the issue is now fixed.  Thanks for reporting it.

    • Like 2

  10. 25 minutes ago, Vincent Parrett said:

    The one that embarcadero created will be used first, the synedit one will be ignored. Which helper is used is dependant on where they are decleared, since embarcadero declared theirs closest to the actual class declaration theirs will be seen first rather than the one on synedit. 

    Actually it is the other way round.   From the docs:

     

    Quote

    You can define and associate multiple helpers with a single type. However, only zero or one helper applies in any specific location in source code. The helper defined in the nearest scope will apply. Class or record helper scope is determined in the normal Delphi fashion (for example, right to left in the unit's uses clause).

    but "nearest scope" means closer to where the variable is declared.

     

    Just to prove:

     

    Project File:

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      System.SysUtils,
      Unit1 in 'Unit1.pas';
    
    type
      MyRecHelper2 = record helper for MyRec
        procedure SayHi;
      end;
    
    { MyClassHelper1 }
    
    procedure MyRecHelper2.SayHi;
    begin
      WriteLn('Hello!');
    end;
    
    var
      Rec: MyRec;
    
    begin
      Rec.SayHi;
      ReadLn;
    end.

    Unit 1

     

    unit Unit1;
    
    interface
    
    type
    
      MyRec = record
    
      end;
    
      MyRecHelper1 = record helper for MyRec
        procedure SayHi;
      end;
    
    implementation
    
    { MyClassHelper1 }
    
    procedure MyRecHelper1.SayHi;
    begin
      WriteLn('Hi!');
    end;
    
    end.

    Output:

    Hello!

     


  11. 11 minutes ago, Vincent Parrett said:

    the best option would be to change SetAdditionalPCREOptions to AddRawOptions - then it will compile in all supported versions.

    What happens then in Delphi 11.2?   Which record helper will be active?  I thought you are not allowed to have two helpers for the same class in the same scope?


  12. I am having issues upgrading to 11.2.   I run the Web Installer keeping the registry options.  It appears to be going smoothly , uninstalling the previous version, then showing a message "Installing Main Application files" and in a few seconds it stops with a message "installation finished".

     

    I can see the application files in the Programs directrory, it even installs a shortcut on the desktop.  But at the end of the installation I can see a running process bds.exe, that does nothing.  If I end the process and try to run Rad Studio from the shortcut the bds.exe process starts but nothing happens.

     

    I remember that with previous version upgrades it would ask me for personalities and download tons of stuff from the cloud.   This time nothing of the sort.

     

    Any clues?

     

    Update:  The issue was related to addins.   After removing the references to Beyond Compare, Parnassus and Gexperts, bds.exe started and allowed me to select platforms.   It is now downloading and installing OK.  And it works well.

     

     


  13. This is a code fragment that shows you how to convert python strings to Delphi strings with PyArg_ParseTuple


     

    function ShowMessage_Wrapper(pself, args: PPyObject): PPyObject; cdecl;
    var
      LMsg: PAnsiChar;
    begin
      with GetPythonEngine do
      begin
        if PyArg_ParseTuple(args, 's:ShowMessage', @LMsg) <> 0 then
        begin
          ShowMessage(Utf8ToString(LMsg));
          Result := GetPythonEngine.ReturnNone;
        end else
          Result := nil;
      end;
    end;

     

    Also have a look at the PyArg_ParseTuple documentation.

     

     

    Using such methods is the low level approach to exposing Delphi code to python.    Please have a look at WrapDelphi demos and tutorials for a high-level approach that that does not require you to use PyArg_ParseTuple or worry about reference counting and the like.  

    • Like 2
×