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

Easily Create Python Delphi Variables In Delphi Using Python4Delphi Sample App

As we know, a Variable stores a value so that you can reuse it later in your program. This reduces redundancy, improves performance, and makes your code more readable. What is Python Delphi Variable? This post will guide you to understand. You can also use Python4Delphi with C++Builder.

Python4Delphi Demo3 Sample App shows how to create a Python Delphi Variable in Delphi using the TPythonDelphiVar component(convert the python variable to the Delphi variable and vice versa), shows the variable type and the value assigned to it, reassign different type value to the same variable, show the variable content in a message. You can find the Demo3 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. Check Demo1 and Demo2 which covers how to run a python script and evaluate an expression in Delphi.

Components used in Python4Delphi Demo3 Sample App:

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

Implementation Details:

In Python, variables need not be declared or defined in advance, as is the case in Delphi. To create a variable, you just assign it a value and then start using it. A variable may be assigned a value of one type and then later re-assigned a value of a different type.

[crayon-673f99e319402767520847/]

Load the custom script to the Memo1 from a file using the code,

[crayon-673f99e319403670478106/]

Save the Script to the file using the code,Delphi/Pascal

[crayon-673f99e319404111542669/]

Show the later assigned value after clicking Execute Script using the below code upon clicking Show var content.

[crayon-673f99e319405692677683/]
<strong>Python4Delphi Demo03<strong>

Check some of the tutorials available for Python4Delphi here

Exit mobile version