Delphi Python: Getting Started with DelphiVCL II: Breakdown The Form Components

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Python: Getting Started with DelphiVCL II: Breakdown The Form Components
By Muhammad Azizul Hakim March 10, 2021

This Section will break down the code example to create a simple Form app as presented in Section 5. These steps are essential for Python Developers to be familiar with Delphi VCL methods, events, and properties, to enable you in creating professional Windows Apps, without installing Delphi.

Below are the explanations of code example in Section 5:
  • Import the module:
Python:
from DelphiVCL import *
  • Use the Python variables, set methods which are included in DelphiVCL classes (review the Section 4 to see all available methods), like: Form, Edit, Button, ListBox, Application, etc to create Python Objects. See the examples below:
Python:
# Set the Form method as MainForm class
class MainForm(Form)

# Set the Edit method
self.edit1 = Edit(self)

# Set the Button method
self.button1 = Button(self)

# Set the ListBox method
self.lb1 = ListBox(self)

# Set the Application method to encapsulate a windowed application. The Application method reflects the fundamentals established in the Windows operating system to create, run, sustain, and destroy an application.
def main():
    Application.Initialize()
    Application.Title = "My DelphiVCL App"
    f = MainForm(Application)
    f.Show()
    FreeConsole()
    Application.Run()
main()
  • Use the Python variables to set events for needed actions. In this example, a button click for adding items:
Код:
def Button1Click(self, Sender):
    self.lb1.Items.Add(self.edit1.Text)
  • Set the properties of Python Objects using SetProps(propertyname = propertyvalue,…N) or each property one by one. Define events and custom methods required to manipulate the GUI events and operations in the script. Here is the example:
Python:
# Set the Caption for the Window
self.Caption = "A VCL Form..."

# Set the size of the Window
self.SetBounds(10, 10, 340, 410)

# Set the properties for the Button method
self.button1.SetProps(Parent=self, Caption="Add", OnClick=self.Button1Click)