DennisTW 1 Posted August 22, 2022 from the demo, (PyArg_ParseTuple( args, 'Lii',@psort, @i, @j) <> 0) defines a procedure of (handle, i, j : integer). function TThreadSortForm.Module_Swap( pself, args : PPyObject ) : PPyObject; cdecl; var psort: NativeInt; i, j: Integer; begin with GetPythonEngine do begin if (PyErr_Occurred() = nil) and {$IFDEF CPU64BITS} (PyArg_ParseTuple( args, 'Lii',@psort, @i, @j) <> 0) {$ELSE} (PyArg_ParseTuple( args, 'iii',@psort, @i, @j) <> 0) {$ENDIF} then begin TSortThread(psort).VisualSwap(i,j); Result := ReturnNone; end else Result := nil; end; end; How do I define a function (TheKey, TheValue : String) : String; I cannot find the definitions of the second parameter of PyArg_ParseTuple . Share this post Link to post
pyscripter 694 Posted August 22, 2022 (edited) This is a code fragment that shows you how to convert python strings to Delphi strings with PyArg_ParseTuple function ShowMessage_Wrapper(pself, args: PPyObject): PPyObject; cdecl; var LMsg: PAnsiChar; begin with GetPythonEngine do begin if PyArg_ParseTuple(args, 's:ShowMessage', @LMsg) <> 0 then begin ShowMessage(Utf8ToString(LMsg)); Result := GetPythonEngine.ReturnNone; end else Result := nil; end; end; Also have a look at the PyArg_ParseTuple documentation. Using such methods is the low level approach to exposing Delphi code to python. Please have a look at WrapDelphi demos and tutorials for a high-level approach that that does not require you to use PyArg_ParseTuple or worry about reference counting and the like. Edited August 22, 2022 by pyscripter 2 Share this post Link to post