Jump to content
Sign in to follow this  
DennisTW

Can't create TPythonEngine at run-time. Why??

Recommended Posts

Since I need to run Python4Delphi in a separate thread. I first try to modify demo01 of Python4Delphi to  create TPythonEngine and TPythonGUIInputOutput at run time instead of design time.

procedure TForm1.FormCreate(Sender: TObject);
begin


  PythonGUIInputOutput1:= TPythonGUIInputOutput.Create(self);
  PythonGUIInputOutput1.Name := 'PythonGUIInputOutput1';
  PythonGUIInputOutput1.Output := Memo2;

  PythonEngine1 := TPythonEngine.Create(self);
  PythonEngine1.Name := 'PythonEngine1';
  PythonEngine1.IO := PythonGUIInputOutput1;
end;

 

However, when I run the demo01.exe now, it pops up the error "Python is not properly initialized"!!!

 

How do fix it?

My eventual goal is to create TPythonEngine , TPythonGUIInputOutput and other python4delphi components in a separate thread at run time, so as to make python run in its own thread.

Please kindly help.

 

Share this post


Link to post

You are not calling PythonEngine1.Load.
Demo34 shows how to load a python engine dynamically, but please note that this is very tricky and things can go wrong.

Share this post


Link to post

Tried. There is no method named " PythonEngine1.Load", but I found PythonEngine1.LoadDll and it worked. Thanks.

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  

×