Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can only run DelphiVCL program once in spyder 5.x #7

Open
hsauro opened this issue Jan 14, 2022 · 6 comments
Open

Can only run DelphiVCL program once in spyder 5.x #7

hsauro opened this issue Jan 14, 2022 · 6 comments
Assignees

Comments

@hsauro
Copy link

hsauro commented Jan 14, 2022

I use spyder 5.x (https://www.spyder-ide.org/) a lot as my a Python IDE.

I can write a DelphiVCL program, eg the simple one below. When I run it the first time it shows correctly. If I try to run it again, the screen shows but then instantly closes. In order to get the form to show correctly, I have to restart the python kernel. Not a showstopper but a nuisance for those running code from spyder. Note that the DelpchVCL code runs fine from the command line with python myfile.py. Running Python 64bit 3.8.6 on Windows 10

  from delphivcl import *

  class MainForm(Form):

     def __init__(self, owner):
         self.Caption = "A VCL Form..."
         self.SetBounds(10, 10, 500, 400)
         self.Position = "poScreenCenter"
         self.OnClose = self.__on_form_close    

    def __on_form_close(self, sender, action):
         action.Value = caFree

 def main():
       Application.Initialize()
       Application.Title = "Hello Python"
       Main = MainForm(Application)
       FreeConsole()
       Application.Run()
       Main.Destroy()

  main()
@hsauro
Copy link
Author

hsauro commented Jan 15, 2022

Update: I tried the same python by calling it from pyscripter instead and got the same problem. I also switched to a different python, 3.7, but that didn't make any difference.

@hsauro
Copy link
Author

hsauro commented Jan 15, 2022

Looks like this problem has been observed before:

https://en.delphipraxis.net/topic/3742-delphivcl-fantastic-but-there-are-some-issues/

@lmbelo
Copy link
Member

lmbelo commented Jan 16, 2022

I've not tried it yet, but I'm guessing this is related to the interpreter life cycle. The application can only be initialized once in the interpreter life cycle.
I'm going to try it out and come again with insights.

@lmbelo lmbelo self-assigned this Jan 16, 2022
@lmbelo
Copy link
Member

lmbelo commented Feb 24, 2022

@hsauro can you try to reproduce this issue again?

@breitsch2
Copy link

C:\Program Files\Streaming\IBZ2021\Module2_3>pip uninstall delphivcl
Found existing installation: delphivcl 0.1.31
Uninstalling delphivcl-0.1.31:
Would remove:
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl-0.1.31.dist-info*
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl*
Would not remove (might be manually added):
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl\Win64\DelphiVCL.pyd
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl_init_ - Kopie.py
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl\moduledefs - Kopie.json
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl\moduledefs.json
c:\users\breitsch\appdata\local\programs\python\python37-32\lib\site-packages\delphivcl\moduledefs.log
Proceed (y/n)? y
Successfully uninstalled delphivcl-0.1.31

C:\Program Files\Streaming\IBZ2021\Module2_3>pip install delphivcl
Collecting delphivcl
Downloading delphivcl-0.1.40-cp37-cp37m-win32.whl (2.2 MB)
|████████████████████████████████| 2.2 MB 1.7 MB/s
Installing collected packages: delphivcl
Successfully installed delphivcl-0.1.40
WARNING: You are using pip version 20.1.1; however, version 22.2.2 is available.
You should consider upgrading via the 'c:\users\breitsch\appdata\local\programs\python\python37-32\python.exe -m pip install --upgrade pip' command.

C:\Program Files\Streaming\IBZ2021\Module2_3>

@breitsch2
Copy link

You can unload the DelphiVCL.pyd each time:
`` eg.execStr('vcl4d_filename = delphivcl.file');
println('import name path: '+eg.EvalStr('vcl4d_filename'));
eg.execStr('dll = ctypes.CDLL(vcl4d_filename)');

//https://stackoverflow.com/questions/46450368/removing-loaded-pyd-files
 eg.execStr('if vcl4d_filename.endswith("pyd"):  '+LF+
           '  _ctypes.FreeLibrary(dll._handle)  '+LF+
           '  _ctypes.FreeLibrary(dll._handle)  ');
println('unload `VCL4Python');`

Tested in maXbox4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants