freelanceprogrammers.org Forum Index » Delphi

how to create a TPythonEngine object?

View user's profile Post To page top
daydaysy Posted: Tue Dec 05, 2006 8:07 am


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!
Reply with quote
Send private message
View user's profile Post To page top
jobbyworld2 Posted: Fri Dec 08, 2006 6:19 pm


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!
>
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Sun Dec 10, 2006 9:50 pm


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!
> >
>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

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
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