标签: python4delphi

Python4Delphi:在函数中返回python对象.(DelphiWrapper)

我正在使用python4delphi.如何从包装的Delphi类函数返回一个对象?

代码片段:

我有一个简单的Delphi类,我将其包装到Python脚本中,对吧?

TSimple = Class
Private
  function getvar1:string;
Public    
Published
  property var1:string read getVar1;
  function getObj:TSimple;
end;
... 
function TSimple.getVar1:string;
begin
  result:='hello';
end;
function TSimple.getObj:TSimple;
begin
  result:=self;
end;
Run Code Online (Sandbox Code Playgroud)

我使用了类似于demo32的TPySimple来提供对Python代码的类访问.我的Python模块名称是test.

TPySimple = class(TPyDelphiPersistent)
  // Constructors & Destructors
  constructor Create( APythonType : TPythonType ); override;
  constructor CreateWith( PythonType : TPythonType; args : PPyObject ); override;
  // Basic services
  function  Repr : PPyObject; override;

  class function  DelphiObjectClass : TClass; override;
end;
...

{ TPySimple }

constructor TPySimple.Create(APythonType: TPythonType);
begin
  inherited;
  // we …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-xe2 python4delphi

5
推荐指数
1
解决办法
1602
查看次数

如何使用Python4Delphi从Delphi返回列表到Python

使用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()
Run Code Online (Sandbox Code Playgroud)

从Python调用时返回'NoneType'.如果将PPyObject更改为诸如整数,AnsiString或double之类的类型,则Python会选择正确的类型并正确显示它.我用

  GetPythonEngine.AddMethod ('callMethod', @TDelphiAPI.callMethod, 'callMmethod)');
Run Code Online (Sandbox Code Playgroud)

从Delphi公开方法.但是,据我所知,没有办法为参数或返回类型指定类型.

我想知道是否有人从delphi python类型返回,如列表甚至numpy数组?

delphi python4delphi

5
推荐指数
1
解决办法
370
查看次数

使用Delphi创建Python扩展

我正在尝试使用Python4Delphi将Python函数转换为Delphi(以教育自己并获得速度,我希望如此).但是我不知道它如何与Delphi和Python一起工作.这是我原来的功能:

def MyFunc(img, curve):
  C = 160
  for i in xrange(img.dim()[0]):
    p = img[i]
    img[i] = (p[0], p[1], p[2] - curve[p[0]] + C)
Run Code Online (Sandbox Code Playgroud)

(Img不是python列表,而是自定义对象)

我从Python4Delphi找到了相关的Demo09,但找不到任何帮助如何通过该列表,解压缩元组并修改值.

文档创建扩展的任何指针?

python delphi python4delphi

3
推荐指数
1
解决办法
2789
查看次数

标签 统计

delphi ×3

python4delphi ×3

delphi-xe2 ×1

python ×1