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

Quickly Learn How To SubClass A Python Type Created In Delphi With This Windows Sample App

Earlier we have learned how to create a new Python Type using Delphi classes. How about inheriting Python Type created in Delphi using a simple python script? This post will guide you to do that using Python4Delphi Sample App. You can also use Python4Delphi with C++Builder.

Python4Delphi Demo26 Sample App shows how to create a Module, Python type, Import the module, and Python Type in a python script, subclass the created Python Type and use it. You can find the Demo26 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 Demo26 Sample App:

You can find the Python4Delphi Demo26 sample project from the extracted repository ..Python4DelphiDemosDemo26.dproj. Open this project in RAD Studio 10.4.1 and run the application.

Implementation Details:

[crayon-672a24424c263788389087/]

Which in turn executes the below python script mentioned in memo1. The script has a class definition MyPoint which is subclassed from a Python Type Name (Point) created in Delphi.

[crayon-672a24424c26b338448044/]
<strong>Python4Delphi Demo26<strong>

Note: To print the DelphiPoint.X and DelphiPoint.Y values, include print(spam.myPoint) in the script and execute.

Exit mobile version