English 中文(简体)
1. 以Delphi创建沙丘延伸
原标题:Creating Python extension with Delphi

我希望,我试图将沙尔职能转至Delphi4Delphi(教育我,并加快速度)。 然而,我不知道这如何与Delphi和Adhury打交道。 我的原始职能如下:

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)

(Img is not python list, but custom object)

我发现有关Demo09号从4Delphi那里获得,但 could无法找到任何帮助,如何填写这份清单,不包装图和修改价值。

任何文件点都会造成延期?

问题回答

粉碎4Delphi处理将灰尘主要DLL装入德尔菲方案的问题,将“灰色”译法纳入你们的德尔菲应用,但也有一些变质;用Delphi书写一个延伸。 以下是一些工作实例守则。

Iampe 第469页,载于Mark Hammond &Andy Robinson(O Reilly)。

A sample DLL skeleton for a Delphi DLL that implements a python extension might look like this, taken from the Demo09 folder in Python4Delphi source distribution:

项目档案来源:

library demodll;

{$I Definition.Inc}

uses
  SysUtils,
  Classes,
  module in  module.pas ;

exports
  initdemodll;
{$IFDEF MSWINDOWS}
{$E pyd}
{$ENDIF}
{$IFDEF LINUX}
{$SONAME  demodll }

{$ENDIF}

begin
end.

实际推广单位(模块.pas):

unit module;

interface
uses PythonEngine;

procedure initdemodll; cdecl;

var
  gEngine : TPythonEngine;
  gModule : TPythonModule;

implementation

function Add( Self, Args : PPyObject ) : PPyObject; far; cdecl;
var
  a, b : Integer;
begin
  with GetPythonEngine do
    begin
      if PyArg_ParseTuple( args,  ii:Add , [@a, @b] ) <> 0 then
        begin
          Result := PyInt_FromLong( a + b );
        end
      else
        Result := nil;
    end;
end;

procedure initdemodll;
begin
  try
    gEngine := TPythonEngine.Create(nil);
    gEngine.AutoFinalize := False;
    gEngine.LoadDll;
    gModule := TPythonModule.Create(nil);
    gModule.Engine := gEngine;
    gModule.ModuleName :=  demodll ;
    gModule.AddMethod(  add , @Add,  add(a,b) -> a+b  );
    gModule.Initialize;
  except
  end;
end;

initialization
finalization
  gEngine.Free;
  gModule.Free;
end.

请注意,可从python中提用的方法只能具有参数:sol, Args :PPyObject,作为参数签字,Args值是Adhurtuple(一种与病媒或阵列相类似的可变数据结构)。 之后,你必须穿透镜头,在校内将提出1个或更多不同类型的论据。 那么,你必须处理以下事实:在座标内的每一件物品都可能是一种愤怒、扼杀、图谋、清单、字典等。

你们需要学会像在座标上一样,在 object物上使用一种方法:img.dim(),从清单中获取物品等等。

看看<代码>PyArg_ParseTuple的哪里定义了(ctrl-click it),并寻找其他方法,首先采用<代码>Py,这些方法的名称可能包括PyList_GetItem。 这是假歌(PyCATEGORY_MethodName)使用的假装-OOP命名公约。 一旦看到一些样本代码,这完全容易。 可悲的是,大多数样本代码都在C。

你可能甚至会利用一种工具,将上面的沙捞越法变成C法典样本,然后试图按行文将它变成Avhur。 但这一切令我感到浪费时间。

另有一些陈列镜的功能是:

Py_BuildValue - useful for return values

Py_INCREF and Py_DECREF - necessary for object reference counting.

You will need to know all the memory rules, and ownership rules here.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签