You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been a large number of enhancements implemented in the Python for Delphi library recently. This discussion provides an overview of these developments.
Support for python's buffer protocol. Demo 35 shows how to use it to get super fast read/write access to numpy arrays.
New convenience function SafePyEngine and ThreadPythonExec for facilitating the execution of python code in Delphi threads. Running python code in Delphi threads. #444 provides a comprehensive guide of how to safely execute python code in threads.
The WrapDelphi unit allows you to easily wrap your Pascal classes, objects, records and interfaces and expose them to python. It is the technology that makes it possible to expose the whole of Vcl and Fmx to python as extension modules. Over the last couple of months, it has been enhanced and expanded in a number of important ways. Here follows a summary of the new features.
A new generic class wrapper TPyClassWrapper<T: class> makes it very easy to wrap Delphi classes, without having to create TRegisteredUnit descendants and implementing RegisterWrappers. See below for an example of how to use it.
Delphi classes are now exposed as first-class python types. This means that you can use the python functions isinstance. issubclass, dir with them and you can call their class methods. Here is an example:
class TTest
classprocedureDoSomething;
classprocedureDoSomethingElse; static;
end;
// In FormCreate
PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TTest>).Initialize;
Class references are also fully supported as function arguments and function results.
Class methods and properties are automatically exposed at the class (python type) level. You no longer need to manually expose classes using RegisterMethods, RegisterGetSets etc. Credit to @lmbelo for coming up with the idea and an initial implementation.
Published class events are handled automatically. There is no need to create and register TEventHandler subclasses. This includes events that have var parameters. See the unit tests.
Functions and procedures with var and out parameters are now fully supported. Here is an example of how to use them:
class TTest
classprocedureFunc1(var I: Integer): Integer;
classprocedureProc(var S: string);
end;
Automatic wrapping of indexed properties including the handling of default properties. See the related unit test.
Studying the unit tests for WrapDelphi will help you to better understand how to use the above enhancements, as well as the other features of WrapDelphi.
Just tested with the 64bit maXbox and Python 3.12 got a
debug: AssertionError: SRE module mismatch 0 err:20
but I think its the missing path environment cause we do have different installs:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Recent enhancements to P4D
There have been a large number of enhancements implemented in the Python for Delphi library recently. This discussion provides an overview of these developments.
Python API encapsulation enhancements
SafePyEngine
andThreadPythonExec
for facilitating the execution of python code in Delphi threads. Running python code in Delphi threads. #444 provides a comprehensive guide of how to safely execute python code in threads.Wrapping of Delphi classes and objects
The WrapDelphi unit allows you to easily wrap your Pascal classes, objects, records and interfaces and expose them to python. It is the technology that makes it possible to expose the whole of Vcl and Fmx to python as extension modules. Over the last couple of months, it has been enhanced and expanded in a number of important ways. Here follows a summary of the new features.
A new generic class wrapper
TPyClassWrapper<T: class>
makes it very easy to wrap Delphi classes, without having to create TRegisteredUnit descendants and implementing RegisterWrappers. See below for an example of how to use it.Delphi classes are now exposed as first-class python types. This means that you can use the python functions
isinstance
.issubclass
,dir
with them and you can call their class methods. Here is an example:Then in your python code:
Class references are also fully supported as function arguments and function results.
Class methods and properties are automatically exposed at the class (python type) level. You no longer need to manually expose classes using RegisterMethods, RegisterGetSets etc. Credit to @lmbelo for coming up with the idea and an initial implementation.
Published class events are handled automatically. There is no need to create and register TEventHandler subclasses. This includes events that have var parameters. See the unit tests.
Functions and procedures with var and out parameters are now fully supported. Here is an example of how to use them:
Then in your python code:
Automatic wrapping of indexed properties including the handling of default properties. See the related unit test.
Studying the unit tests for WrapDelphi will help you to better understand how to use the above enhancements, as well as the other features of WrapDelphi.
Beta Was this translation helpful? Give feedback.
All reactions