Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn About Using Delphi Methods As Python Functions With Python4Delphi Sample App

Earlier we have seen how to add methods in Python Module using Python4Delphi TPythonModule component’s Add Method. However, the Add Method parameter uses a PyCFunction type parameter. In many cases, we may need to define the method which should return Delphi Type. How to do that? This post will provide a way to do that using the TPythonModule component itself. You can also use Python4Delphi with C++Builder.

Python4Delphi Demo7 Sample App shows how to create a Module, add a Delphi Method to that module, Import the module in a python script, and access the added routine. You can find the Demo7 source on GitHub.

Prerequisites: Download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out this video Getting started with Python4Delphi.

Components used in Python4Delphi Demo5 App:

Note: This Demo also uses TPythonType component but this post doesn’t cover that. To learn about TPythonType check this post.

You can find the Python4Delphi Demo7 sample project from the extracted GitHub repository ..\Python4Delphi\Demos\Demo07.dproj. Open this project in RAD Studio 10.4.1 and run the application.

Implementation Details:

[crayon-672a8b6237287828269594/]
[crayon-672a8b623728f294739095/]
<strong>Python4Delphi Demo7<strong>

Check some of the tutorials available for Python4Delphi here

Exit mobile version