peardox 0 Posted July 1, 2022 (edited) Some sample python... import adelphimodule class ADict(dict): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.__dict__ = self someitems = ADict( first = 1, second = "Two", third = 3.0, fourth = ADict( subitem1 = True } ) print(adelphimodule.delphievent(someitems)) Now, in Delphi I stick a PythonModule on a form and hook it up to engine etc (i.e. all this bit works) - I name it delphimodule which will then make it accessible with the Python above. Next I create an event for the module called delphievent In delphi I run the Python and when it hits the adelphimodule.delphievent(someitems) which then triggers this bit of Delphi... procedure TForm1.PythonModule1Events0Execute(Sender: TObject; PSelf, Args: PPyObject; var Result: PPyObject); var log: TTrainLog; begin with GetPythonEngine do begin // Check if the transmitted object is a dictionary if not PyDict_Check(Args) then begin Result := PyUnicodeFromString('===> Bad Event Handler!'); Exit; end; end; Result := PyUnicodeFromString('===> Good Event Handler!'); end; This code will make the Python print "Bad Event Handler" even though I've passed the event data that is a Python dict The examples have a single event demo and it does nothing with passing data so I'm a little stumped over how to extract the data I passed in I could write yet another module I guess but then I'd end up needing new modules for any new bunch of data I sent back to Delphi. The thing I'm trying to do is pass arbitary data back to delphi (tried packaging it as JSon but couldn't read ther string data either) Edit : Got string passing OK now so can always pass as JSON Edited July 2, 2022 by peardox Share this post Link to post
pyscripter 689 Posted July 6, 2022 Args is a tuple not a dictionary. Search in the P4D source code for PyArg_ParseTuple to see how to make use of Args. There are hundreds of examples! Share this post Link to post