RAD Studio with Delphi is a powerful Integrated Development Environment (IDE) for creating applications in the Object Pascal programming language. It enables developers to create cross-platform applications with UIs using two libraries: Visual Component Library (VCL) and FireMonkey (FMX). This article will go over the fundamentals of DelphiVCL and DelphiFMX and how to install and test these Delphi libraries and use them in your Python apps to create rich user interfaces and add the additional power they bring to your own projects.
Table of Contents
What is Delphi For Python?
DelphiVCL for Python is a Python wrapper around Delphi’s native Windows GUI framework, VCL. VCL is designed for Windows and makes use of native Windows controls. This means that developers can use Python to create Windows desktop applications while still reaping the benefits of the powerful Delphi IDE. DelphiVCL for Python includes many components and controls for creating feature-rich and visually appealing user interfaces for Windows applications.
DelphiFMX for Python, on the other hand, is a binding of the FireMonkey cross-platform GUI framework (FMX). The FMX framework is compatible with the most popular operating systems, including Windows, macOS, iOS, and Android. This means developers can use Python to create cross-platform applications while utilizing the powerful Delphi IDE. In addition, DelphiFMX for Python includes components and controls for creating user interfaces that look and behave consistently across platforms.
While developers can create GUI applications without knowing or installing Delphi, they must install the delphifmx
and delphivcl
Python packages to use DelphiFMX and DelphiVCL. Much of what developers learn with Delphi for Python will transfer to the other package. Still, there may be some cases where developers prefer the lighter-weight VCL framework when creating Windows applications because it is specifically designed for the Windows platform.
How to install DelphiFMX and DelphiVCL libraries for Python?
There are two ways to install the Delphi libraries: using PyPi or downloading the source from GitHub. DelphiFMX and DelphiVCL are available on PyPi and support Python 3.6 through 3.10, including Conda. In addition, DelphiFMX works with various operating systems, including Android32, Android64, Linux64, OSX64, OSXARM64, Win32, and Win64, whereas DelphiVCL is only available for Windows.
The simplest way to install these libraries is through PIP. For DelphiFMX, use this command:
1 2 |
pip install delphifmx |
For DelphiVCL, use the command:
1 2 |
pip install delphivcl |
Alternatively, download or clone the repository from GitHub and manually install the package. Once the repository has been downloaded or cloned, navigate to the DelphiFMX4Python or DelphiVCL4Python root directory and open the command or Conda prompt with that path. Finally, to install the package, run the following command:
1 2 |
python setup.py install |
How can I test if the Installation of DelphiFMX and DelphiVCL in Python was successful?
To see if the delphivcl
and delphifmx
modules were successfully installed, use the Python REPL and enter the dir()
function to look for available names in the local scope. Then, import the installed modules and see if they appear in the dir()
function output. To validate the installation, use the dot (.
) operator to look for available classes, functions, and objects in the installed modules. An object Application
instance is a ready-to-use singleton instance that can be accessed via the dot (.
) operator.
Let’s look at this in action using the terminal:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# Enter the Python REPL $ python # Check available names in the local scope >>> dir() ['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__'] # Import the installed modules >>> import delphifmx >>> import delphivcl # Check available names in the local scope again >>> dir() ['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'delphifmx', 'delphivcl'] # Check for available classes, functions, and objects in the modules using the dot operator >>> delphifmx.Button <class 'Button'> >>> delphivcl.Button <class 'Button'> |
In this example, we first entered the Python REPL and used the dir()
function to search the local scope for available names. Next, we checked for available names in the local scope again after importing the installed delphifmx
and delphivcl
modules to confirm that the modules were successfully installed.
Finally, we used the dot operator to search the modules for available classes, functions, and objects, such as Button
. If the modules were not properly installed, the code would throw an ImportError
when attempting to import them or an AttributeError
when attempting to access non-existent classes, functions, or objects.
How to create a simple app with the DelphiVCL Python libraries?
Let’s now create a simple GUI application. The code for it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# Import the delphivcl library from delphivcl import * # Initialize the application Application.Initialize() # Set the title of the application to "Hello DelphiVCL" Application.Title = "Hello DelphiVCL" # Create a new form window app = Form(Application) # Set the caption of the form window to "Welcome" app.SetProps(Caption = "Welcome") # Show the form window app.Show() # Free the console FreeConsole() # Run the application Application.Run() # Destroy the form window app.Destroy() |
How to create a simple app with the DelphiFMX Python libraries?
We’ve seen an example for DelphiVCL. Now, let’s get you started with the DelphiFMX
Python package to build GUI applications. For this, let’s create an FMX version of the above-created simplest VCL application using the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# Import the delphifmx library from delphifmx import * # Initialize the application Application.Initialize() # Set the title of the application to "Hello DelphiFMX" Application.Title = "Hello DelphiFMX" # Create a new form window app = Form(Application) # Set the caption of the form window to "Welcome" app.SetProps(Caption = "Welcome") # Set the main form of the application to the new form window Application.MainForm = app # Show the form window app.Show() # Run the application Application.Run() # Destroy the form window app.Destroy() |
Some differences exist between the DelphiVCL version of the simplest app and this DelphiFMX code. For example, in the DelphiVCL code, the MainForm
property is automatically set to the first form created in the application. We need to explicitly call the FreeConsole()
function to release the console window’s resources.
On the other hand, in the DelphiFMX code, we need to set the Application.MainForm
to explicitly specify which form should be the main form, and the FreeConsole()
function is called automatically in DelphiFMX. These differences in the two frameworks’ handling of creating and managing the user interface and other application resources may influence the choice of framework developers to use based on their requirements and familiarity with the respective frameworks.
Are you ready to make your own GUIs with Delphi and Python?
DelphiVCL and DelphiFMX are powerful libraries for creating cross-platform applications with rich UIs. DelphiVCL is a standard library containing many pre-built user interface controls for creating desktop applications. DelphiFMX, on the other hand, is a more modern library that enables developers to create user interfaces for mobile and desktop applications from a single codebase. Python developers can easily install Delphi libraries and create simple applications using DelphiVCL and DelphiFMX for Python with the help of this article. It is now up to you to investigate more of Delphi’s capabilities and create user interfaces with Delphi.
Check out our comprehensive ebook, “Getting Started with Python GUI,” to learn more about creating GUIs with Python. This ebook will walk you through the fundamentals of creating user interfaces with Python and Delphi, laying the groundwork for you to build more complex applications.
Click the link to get your copy today and take your Python programming skills to the next level.
What are some FAQs about DelphiVCL and DelphiFMX?
What is the difference between DelphiVCL and DelphiFMX?
The VCL library closely encapsulates the Microsoft Windows GUI controls to make it very east to develop powerful Windows desktop applications. In contrast, FMX allows developers to create cross-platform user interfaces for mobile and desktop applications from a single codebase. FMX creates controls using its own graphics technology and custom drawing whereas VCL partially relies on the Windows APIs to render the controls. Both are very powerful. DelphiVCL and DelphiFMX are the Python versions of the VCL and FMX frameworks found in the RAD Studio with Delphi ecosystem.
Can I use DelphiVCL and DelphiFMX together?
Yes, DelphiVCL and DelphiFMX can be used by developers to create hybrid applications that run on both desktop and mobile platforms.
How do I install DelphiVCL and DelphiFMX?
DelphiVCL and DelphiFMX are pre-installed in the Delphi IDE, so developers can use them immediately.
What platforms are supported by DelphiVCL and DelphiFMX?
DelphiVCL is compatible with desktop platforms such as Windows, whereas DelphiFMX is compatible with desktop and mobile platforms such as Android, iOS, and macOS.
What kind of applications can I build with DelphiVCL and DelphiFMX?
Python developers can use DelphiVCL and DelphiFMX to create various applications such as currency converter, employee management systems, to-do apps, guessing games, tic-tac-toe, TUIs, and much more.
Are any resources available to help me learn more about DelphiVCL and DelphiFMX?
Numerous online resources, such as documentation, tutorials, and forums, help developers learn more about DelphiVCL and DelphiFMX and how to use them effectively. The ebook also contains detailed instructions and step-by-step tutorials for DelphiVCL and DelphiFMX.