freelanceprogrammers.org Forum Index » Delphi
how to create a TPythonEngine object?
Joined: 21 May 2005
Posts: 13
how to create a TPythonEngine object?
When I drag a TPythonEngine onto a form at design time, everything is
OK. But when I tried to create a TPythonEngine through its constructor
explicitly, I got a runtime error which said "Python is not properly
initialized". My code is like the following:
var
pe:TPythonEngine;
begin
pe:=TPythonEngine.Create(nil);
try
pe.ExecString(`a=1+1`);
finally
pe.Free;
end;
end;
How can I make the code work? Is there anything I should take care of?
Thank you!
Joined: 23 Oct 2006
Posts: 5
how to create a TPythonEngine object?
i think you should be inspirate by demo9 :
procedure initdemodll;
begin
try
gEngine := TPythonEngine.Create(nil);
gEngine.AutoFinalize := False;
//--------------------
gEngine.LoadDll; <-- !!!!!!!!!!!
//--------------------
gModule := TPythonModule.Create(nil);
gModule.Engine := gEngine;
gModule.ModuleName := `demodll`;
gModule.AddMethod( `add`, @Add, `add(a,b) -> a+b` );
gModule.Initialize;
except
end;
end;
Good Dev with P4D.
--- In pythonfordelphi@yahoogroups.com, "daydaysy" <ildg@...> wrote:
>
> When I drag a TPythonEngine onto a form at design time, everything is
> OK. But when I tried to create a TPythonEngine through its constructor
> explicitly, I got a runtime error which said "Python is not properly
> initialized". My code is like the following:
>
> var
> pe:TPythonEngine;
> begin
> pe:=TPythonEngine.Create(nil);
//*******************add this
pe.LoadDll;
//*********************************************
> try
> pe.ExecString(`a=1+1`);
> finally
> pe.Free;
> end;
>
> end;
>
> How can I make the code work? Is there anything I should take care of?
> Thank you!
>
Joined: 29 Apr 2005
Posts: 103
how to create a TPythonEngine object?
Note that "gEngine.AutoFinalize := False;" is only required for dll
pluging (demo9) but not if you want to create the engine in your main
application.
--- In pythonfordelphi@yahoogroups.com, "jobbyworld2" <jobbyworld@...>
wrote:
>
> i think you should be inspirate by demo9 :
>
> procedure initdemodll;
> begin
> try
> gEngine := TPythonEngine.Create(nil);
> gEngine.AutoFinalize := False;
> //--------------------
> gEngine.LoadDll; <-- !!!!!!!!!!!
> //--------------------
> gModule := TPythonModule.Create(nil);
> gModule.Engine := gEngine;
> gModule.ModuleName := `demodll`;
> gModule.AddMethod( `add`, @Add, `add(a,b) -> a+b` );
> gModule.Initialize;
> except
> end;
> end;
>
> Good Dev with P4D.
>
>
>
> --- In pythonfordelphi@yahoogroups.com, "daydaysy" <ildg@> wrote:
> >
> > When I drag a TPythonEngine onto a form at design time, everything is
> > OK. But when I tried to create a TPythonEngine through its constructor
> > explicitly, I got a runtime error which said "Python is not properly
> > initialized". My code is like the following:
> >
> > var
> > pe:TPythonEngine;
> > begin
> > pe:=TPythonEngine.Create(nil);
>
>
> //*******************add this
> pe.LoadDll;
> //*********************************************
> > try
> > pe.ExecString(`a=1+1`);
> > finally
> > pe.Free;
> > end;
> >
> > end;
> >
> > How can I make the code work? Is there anything I should take care of?
> > Thank you!
> >
>
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







