[Delphi]Python For Delphi使用大全 (转)

原始地址:http://blog.csdn.net/kernelspirit/article/details/760413

Python For Delphi搭建了Delphi和强大的脚本语言Python的桥梁,使用起来非常方便,让Delphi华丽的界面配合Python强大、简洁、稳定的后台逻辑处理能力,让应用程序模块清晰、界面漂亮、后台复杂逻辑不再复杂,大幅提高开发效率。使用的时候出现了一些容易忽视造成的问题,现总结如下。

版本

Python For Delphi支持的Python版本为2.3,而最新最稳定的Python是2.4,使用时会提示找不到python23.dll的错误。按下述方法解决:

设置TPythonEngine的属性,DllName设为python24.dll,RegVersion设为2.4,最关键的是UseLastKnownVersion设为False,不然DllName,RegVersion是不起作用的。

 

OnPathInitialization

OnPathInitialization是TPythonEngine设置Python路径的时候调用的事件,但有时却不调用,怎么回事呢?

原来TPythonEngine在初始化的时候首先查找注册表中有没有对应的路径设置信息,如果有,则直接从注册表读取而不再执行OnPathInitialization,如TPythonEngine的RegVersion为2.4,它就去注册表查找是否有[HKEY_LOCAL_MACHINE/SOFTWARE/Python/PythonCore/2.4/PythonPath],如果有直接读取,没有调用OnPathInitialization,在OnPathInitialization中可以通过程序设置Python的库路径,设置成功后会写入注册表。

 

分发

1、 安装整个标准Python模块、库,即Lib目录。

2、 选择性的安装整个DLLs目录下的Python标准模块。

3、 安装python24.dll到系统目录,如c:/winnt/system32。

4、 在自己写的Delphi程序中,用TPythonEngine的OnPathInitialization事件设置Lib和DLLs的路径,并且将自己编写的模块所在的目录也加到路径中。

注意:每个路径都要用分号分隔(’;’)。

转载于:https://www.cnblogs.com/ctracerpp/p/4376991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PythonForDelphi 修改 最后修改日期2019-2-1这一版,需要注意的是python 3.7 要安装32位版 需要在Delphi中先安装上PythonForDelphi控件包,安装不麻烦,可参考上述资料的说明文档. 包含34个例程源码几乎涵盖了Python4Delphi的所有方面. Demo01 A simple Python evaluator Demo02 Evaluate a Python expression Demo03 Defining Python/Delphi vars Demo04 Defining Python/Delphi vars (advanced case) Demo05 Defining a new Module Demo06 Defining a new Type Demo07 Using Delphi methods as Python functions Demo08 Using Delphi classes for new Python types Demo09 Making a Python module as a Dll Demo10 Mapping Delphi VCL components inside Python using TPythonDatabase (BDE - not changed) Demo10_FireDAC Database demo using FireDAC Demo11 Using Threads inside Python Demo12 Using PythonAtom. -> Deprecated since Delphi 6, See VarPyth instead Demo13 Using TPythonDatabase. (BDE - not changed) Demo14 Making a Dll with TPythonDatabase (BDE - not changed) Demo15 Using a TDataset descendant with Python, except TTable and TQuery. (BDE - not changed) Demo16 Using a TDelphiVar or Module methods ? (Kylix ready) Demo17 Using variant arrays of 2 dimensions (Kylix ready) Demo18 C++ Builder: using the Python Dll in a console application Demo19 C++ Builder: this is a replicate of the Delphi Demo05 Demo20 C++ Builder: this is a replicate of the Delphi Demo08 Demo21 Using Events in TPythonModule or TPythonType (Kylix ready) Demo22 Using Threading, Windows Console and Command line arguments (Kylix ready) Demo23 Using Threading and Delphi log window. (Kylix ready) Demo24 Using TAtomPythonEngine (Deprecated since Delphi 6, See VarPyth instead) Demo25 Using VarPyth.pas (Kylix ready) Demo26 Demo8 revisited to allow the new Python type to be subclassed Demo27 Container indexing Demo28 Iterator (Kylix ready) Demo29 Using Python Imaging Library (PAL) Demo30 Using Named Parameters (Kylix ready) Demo31 Using WrapDelphi to access Delphi Form attributes (Requires Delphi5 or later) Demo32 Demo08 revisited using WrapDelphi (Requires Delphi7 or later) Demo33 Using Threads inside Python Demo34 Dynamically creating, destroying and recreating PythonEngine. Uses PytonVersions
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值