limelect 48 Posted June 21 (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 https://github.com/pyscripter/pyscripter/issues/1286 and this https://github.com/Embarcadero/DelphiVCL4Python/issues/92 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 June 21 by limelect Share this post Link to post
pyscripter 689 Posted June 22 Add f.Free() 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
limelect 48 Posted June 22 (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 June 22 by limelect Share this post Link to post
pyscripter 689 Posted June 22 (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 June 22 by pyscripter Share this post Link to post
limelect 48 Posted June 22 Thanks Ok now I see other examples MainForm.Destroy() At least I have a learning tool P,S https://limelect.com/downloads/python-formater/ can help someone where the formatting is done with autopep8 or Black Why not incorporate this in your software? very handy Share this post Link to post
limelect 48 Posted June 22 (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 June 22 by limelect Share this post Link to post
shineworld 73 Posted June 24 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 super().__init__(owner) ... # set main form events handlers self.OnClose = self.__on_form_close ... def __on_form_close(self, sender, action): if sender is None: return if sender == self: action.Value = caFree ... def main(): # initialize application Application.Initialize() Application.Title = "" # create and show main_view main_view = DesktopView(Application) try: main_view.Show() FreeConsole() Application.Run() finally: main_view.Destroy() # main entry point if __name__ == "__main__": main() Share this post Link to post