freelanceprogrammers.org Forum Index » Delphi
Most simple technique for creating a Callback function (Pyth
Joined: 01 Sep 2006
Posts: 3
Most simple technique for creating a Callback function (Pyth
Hello,
you can find the underlying technique in the PythonEngine and MethodCallback
code modules.
All needed basic Python API functions are imported, so in extreme, you can strip
the PythonEngine to the Interface, starting with the DynamicDLL type.
In Short : You can generate an empty PythonModule with a Call to the Python API
It gets a pointer to the Callback Methods:
function TPythonInterface.Py_InitModule( const AName : PChar; md : PPyMethodDef)
: PPyObject;
begin
CheckPython;
result := Py_InitModule4( AName, md, nil, nil, APIVersion );
end;
The PPyMethodDef is a pointer to an array of callback function structures,
containing pointer to the function,
name in Python and a description string, I never needed.
The Callback function has to be declared as the following:
PyCFunction = function( self, args:PPyObject): PPyObject; cdecl;
To make a method as Callback target, I suggest to use the MethodCallBack unit as
it is used in PythonEngine,
as this is tricky.
The Result of the callback function has always to be a Python Object, Py_None,
if a void function (Link counter
to be incremented!).
The biggest problem are the args to the callback function: They are given as a
Python Tuple, which
has to be decoded with a sscanf like open array mechanism (PyArg_ParseTuple) not
available in Delphi!
A workaround is given in the PythonEngine source, simply look for
PyArg_ParseTuple.
With best regards
Dietmar
P.S. the PythonEngine was made to make such things less painfull :-)
--
Dietmar Budelsky
dbudelsky@...
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







