Recent enhancements #445
pyscripter
announced in
Announcements
Replies: 1 comment 2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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