使用 Python4Delphi,将 Delphi 方法暴露给 Python 是相当简单的,这样 Python 就可以调用 Delphi 应用程序。但是,我无法将由 Delphi 方法创建的 Python 列表返回给 Python。例如:
function TDelphiAPI.callMethod : PPyObject;
begin
// Create a new empty list of three elements
result := GetPythonEngine.PyList_New(3);
end;
import mylib
p = mylib.DelphiAPI()
print p.callmethod()
从 Python 调用时,这将返回“NoneType”。如果将 PPyObject 更改为整数、AnsiString 或 double 等类型,Python 会选择正确的类型并正确显示它。我用
GetPythonEngine.AddMethod ('callMethod', @TDelphiAPI.callMethod, 'callMmethod)');
从 Delphi 公开该方法。但是,据我所知,无法指定参数或返回类型的类型。
我想知道是否有人从 delphi python 类型(例如列表甚至 numpy 数组)返回?