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

Learn How To Use Python Functions With Keyword Arguments In A Delphi Windows App

In Delphi, we pass values to parameters while calling a function in an order the function parameters were defined. This is the same in Python as well called positional arguments. However, Python has additional features passing arguments to the function with Keyword(Named) Arguments. To know more about these Keyword Arguments check here. How to use such Python functions in Delphi? This post will help to understand with Python4Delphi sample app.

Python4Delphi Demo30 Sample App shows how to define a Function with Keyword parameters in Python Main Module, Instantiate in Delphi with Keyword arguments and assert it by accessing the values. You can find the Demo30 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 Demo30 Sample App:

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

Implementation Details:

[crayon-672a3a93eb106380037516/]

Followed by the above script execution, the Person instance is instantiated within the MainModule by passing different keyword arguments in a different order. Each time the value is asserted and the code is shown below. You can ignore to pass any arguments in the available arguments or pass in any order.

[crayon-672a3a93eb10d548962386/]

 

Python4Delphi Demo30
Exit mobile version