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

Easily Create A Python Container Type In Delphi And Execute It In This Windows Sample App

Earlier we learned how to create a Python type using Delphi classes. How about creating a Python type with some containers or collections capabilities in Delphi and accessing its elements? Python4Delphi PyObject contains Type Services routines e.g Basic, Number, Sequence, Mapping which can be overridden with our custom Python Types Delphi classes. This post helps to do that.

Python4Delphi Demo27 Sample App shows how to create a Module, Python type, Import the module, and Python Type in a python script, create a sequence type object and access some of the service routines like length, indexing, etc. You can find the Demo27 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 Demo27 Sample App:

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

Implementation Details:

[crayon-673a447057302316726777/]
[crayon-673a447057309234627372/]
[crayon-673a44705730b372637676/]

Which will execute the python script mentioned below.

[crayon-673a44705730c635203194/]

Note. CreateMySeq in the above script is created automatically by Python4Delphi when the property GenerateCreateFunction of TPythonType1(MySeq) is true.

<strong>Python4Delphi Demo27<strong>

Exit mobile version