Jump to content
Sign in to follow this  

Delphi + Python

Recommended Posts

Posted (edited)

After 30++ years with Delphi and other languages, I decided to learn Python

and see what is all about.

So I used Delphi and some other libraries to learn. (for me Python is awful)

And now to the point

While using DelphiVCL4Python I found that pyscripter  or GuiPy do some closing problems on some application

So I made this


and this



however today I found out that Microsoft Visual Studio 2019  also works on Python

and the program I put closed without any problems

So I wonder where is the problem?

Edited by limelect

Share this post

Link to post


as the last statement of main()

Then it should work as expected.


Application.Free()  instead of f.Free() should also work.



Share this post

Link to post
Posted (edited)

Ok but why in Microsoft Visual Studio 2019

 it closes????


This is a demo taken from Delphi not mine

It works thanks

some applications close without Application.Free() 

Edited by limelect

Share this post

Link to post
Posted (edited)

A unique feature of PyScripter is that, when you run a script, the python process is kept alive at the end of the run.   For example if you run the script:


a = 1


after running you can still see the value of a in the variables window and you can print its value by typing "a" in the interpreter window.   This also allows post-mortem debugging (Run, Post Mortem).


In Visual Studio, the form is destroyed, because the python process ends.   With PyScripter, you have to explicitly destroy the form.

To emulate the behaviour of other IDE's you could do Run, Reinitialize Python Engine at the end of each run.


There were multiple request of emulating the PyScripter way in other IDEs  (e.g. Access python console and program variables after program finished running? – IDEs Support (IntelliJ Platform) | JetBrains  or if you google "python see variables after running").  

Edited by pyscripter

Share this post

Link to post
Posted (edited)

I just found out that Delphi IDE tools export to Python does not

put Application.Free()  So it is Embarcadero's problem

Try it

Edited by limelect

Share this post

Link to post

Do not miss to add OnClose event in the main form and evaluate action for caFree


class DesktopView(Form):

    def __init__(self, owner):
        # call vcl inherited view constructor


        # set main form events handlers
        self.OnClose = self.__on_form_close


    def __on_form_close(self, sender, action):
        if sender is None:

        if sender == self:
            action.Value = caFree


def main():
    # initialize application
    Application.Title = ""

    # create and show main_view
    main_view = DesktopView(Application)

# main entry point
if __name__ == "__main__":


Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this