freelanceprogrammers.org Forum Index » Delphi
Specifying another Python DLL
Joined: 15 Sep 2005
Posts: 12
Specifying another Python DLL
My program is an in-process COM server (ie. a DLL). It uses Python
for Delphi to run some internal scripts. I test my DLL by invoking
its IDispatch interface from a Python test script. That is:
test.py --COM-> api.dll --P4D-> internal py scripts
When I ran this I got errors while initialising the Python DLL from
within P4D. I think the problem was that the DLL had already been
initialised by python.exe.
To get around this I now instruct P4D to use a copy python24.dll that
we install with our application. This DLL is not in the same location
as a normal Delphi installation, which suits us fine because we`d like
to be sure that the version of Python we tested with is the version we
are using for our internal scripts.
This is what I ended up doing:
// Allow us to override the DLL location/name.
u_Engine.UseLastKnownVersion := False;
// Complain if it cannot be found.
u_Engine.FatalMsgDlg := True;
u_Engine.FatalAbort := True;
// Tell P4D where to find the DLL.
u_Engine.DllName := BaseDir+u_Engine.DllName;
It seems to work. Is this the best way?
Oliver
Joined: 29 Apr 2005
Posts: 103
Specifying another Python DLL
> My program is an in-process COM server (ie. a DLL). It uses Python
> for Delphi to run some internal scripts. I test my DLL by invoking
> its IDispatch interface from a Python test script. That is:
>
> test.py --COM-> api.dll --P4D-> internal py scripts
>
> When I ran this I got errors while initialising the Python DLL from
> within P4D.
P4D can work within a Dll. You can have a look at Demo9 which shows how you
can create a Python dll module (pyd).
Basically, you just need to do:
gEngine := TPythonEngine.Create(nil);
gEngine.AutoFinalize := False;
gEngine.LoadDll;
Disabling AutoFinalize is very important because you`re not the owner of the
Python engine.
However, I`m not sure I`ve understood why you have a Python script that uses
COM to invoke some code in a DLL that will run a Python script!
Can`t you have all your scripts running from the main engine and extend
Python with your specific APIs?
> I think the problem was that the DLL had already been
> initialised by python.exe.
Sure, it was.
> To get around this I now instruct P4D to use a copy python24.dll that
> we install with our application. This DLL is not in the same location
> as a normal Delphi installation, which suits us fine because we`d like
> to be sure that the version of Python we tested with is the version we
> are using for our internal scripts.
>
> This is what I ended up doing:
>
> // Allow us to override the DLL location/name.
> u_Engine.UseLastKnownVersion := False;
> // Complain if it cannot be found.
> u_Engine.FatalMsgDlg := True;
> u_Engine.FatalAbort := True;
> // Tell P4D where to find the DLL.
> u_Engine.DllName := BaseDir+u_Engine.DllName;
>
> It seems to work. Is this the best way?
It is, if you want to make sure that you have your own private engine that
nobody else can access.
Note that you can also assign your BaseDir var to the DllPath property of
TPythonEngine. But the result will be the same.
Bye,
Morgan
Joined: 15 Sep 2005
Posts: 12
Specifying another Python DLL
Morgan Martinet wrote:
> However, I`m not sure I`ve understood why you have a Python script
> that uses
> COM to invoke some code in a DLL that will run a Python script!
> Can`t you have all your scripts running from the main engine and extend
> Python with your specific APIs?
The DLL and its internal scripts are my "product", and will be given to
customers. The Python script that invokes them is a black box
regression test; it will never ship to customers. I am using Python
both as a test script language, and internally, because it is such a
good language. Were I a masochist then I could have written the test
script in VB :-)
>> ... It seems to work. Is this the best way?
>
> It is, if you want to make sure that you have your own private engine
> that
> nobody else can access.
Yes, I think this is good for us.
> Note that you can also assign your BaseDir var to the DllPath property of
> TPythonEngine. But the result will be the same.
That is more elegant. Thanks.
Oliver
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







