2005年04月14日 星期四 02:44
请各位指点,谢谢!
delphi 7
python 2.3
win98
Python for Delphi V3.25
问题1:
在delphi里面:
1 创建一个 Form ;
2 创建一个 TMemo(Memo1) 来容纳 python code;
3 创建一个 TPythonInputOutput (PythonInputOutput1) ;
4 创建一个 TPythonEngine (PythonEngine1) ;
5 创建一个 PythonDelphiVar components ,命名为 bx. 设置 VarName 属性
和name属性相同;
6 把TPythonEngine的IO属性连接到TPythonInputOutput;
7 创建一个 TButton (Button1) ;
8 在Memo1中写入python代码 (即设置其lines属性):
def ax(m,n):
y=10
bx.value=y+m+n
...
现在,点击Button1, 怎样调用python代码中的函数ax,传递参数(比如 m=33 and
n=25), 取得 bx.ValueAsString ;
Delphi Code:
---------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, PythonEngine, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
PythonEngine1: TPythonEngine;
bx: TPythonDelphiVar;
PythonInputOutput1: TPythonInputOutput;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
/////////////////////////////////////////////////
// //
// How to call the funtion ax passing the //
// arguments(such as m=33 and n=25), and //
// get bx.ValueAsString ?? //
// //
/////////////////////////////////////////////////
showmessage( bx.ValueAsString );
end;
end.
-------------------------------
问题2:
还有,如果把python代码保存为一个单独的文件,在delphi中调用该文件,并调用
其中的函数,我经过实践,发现python文件只能为.py格式,如果是.pyc,就会失
败,我在google搜索,发现有人也遇到这个问题,但没找到解决办法,请教各位有
无解决办法?具体的delphi代码该如何写?
谢谢!!
2005年04月14日 星期四 10:48
你的PythonDelphiVar有了onchange属性了吧? 调用PYTHON函数可以用DELPHI触发PYTHONEngine来执行字符串或文件,我的做法是把资源读出来,用python引擎执行字符串 On 4/14/05, Tom <myata99 at tom.com> wrote: > 请各位指点,谢谢! > > delphi 7 > python 2.3 > win98 > Python for Delphi V3.25 > > 问题1: > > 在delphi里面: > 1 创建一个 Form ; > 2 创建一个 TMemo(Memo1) 来容纳 python code; > 3 创建一个 TPythonInputOutput (PythonInputOutput1) ; > 4 创建一个 TPythonEngine (PythonEngine1) ; > 5 创建一个 PythonDelphiVar components ,命名为 bx. 设置 VarName 属性 > 和name属性相同; > 6 把TPythonEngine的IO属性连接到TPythonInputOutput; > 7 创建一个 TButton (Button1) ; > 8 在Memo1中写入python代码 (即设置其lines属性): > > def ax(m,n): > y=10 > bx.value=y+m+n > ... > > 现在,点击Button1, 怎样调用python代码中的函数ax,传递参数(比如 m=33 and > n=25), 取得 bx.ValueAsString ; > > Delphi Code: > > --------------------------- > > unit Unit1; > > interface > > uses > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, > Forms, > Dialogs, PythonEngine, StdCtrls; > > type > TForm1 = class(TForm) > Memo1: TMemo; > Button1: TButton; > PythonEngine1: TPythonEngine; > bx: TPythonDelphiVar; > PythonInputOutput1: TPythonInputOutput; > procedure Button1Click(Sender: TObject); > private > { Private declarations } > public > { Public declarations } > end; > > var > Form1: TForm1; > > implementation > > {$R *.dfm} > > procedure TForm1.Button1Click(Sender: TObject); > begin > ///////////////////////////////////////////////// > // // > // How to call the funtion ax passing the // > // arguments(such as m=33 and n=25), and // > // get bx.ValueAsString ?? // > > // // > ///////////////////////////////////////////////// > > showmessage( bx.ValueAsString ); > > end; > > end. > > ------------------------------- > > 问题2: > > 还有,如果把python代码保存为一个单独的文件,在delphi中调用该文件,并调用 > 其中的函数,我经过实践,发现python文件只能为.py格式,如果是.pyc,就会失 > 败,我在google搜索,发现有人也遇到这个问题,但没找到解决办法,请教各位有 > 无解决办法?具体的delphi代码该如何写? > > 谢谢!! > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -- You ask me,me ask who?
2005年04月14日 星期四 14:37
谢谢你! 其实我需要的就是这两个: 1> 调用外部的已编译的.pyc文件(不是.py文件)中的function或者class,取得 返回值; 2> 把python代码粘贴在一个不可见的Memo里面,调用python代码里的function或 者class,取得返回值; 麻烦你说的再详细些,需要哪些Python for Delphi的控件(一共8个),请给一段 具体的代码,只需要最关键的几个语句,我对delphi懂得少,实在不知道该怎样调 用函数和类. 谢谢! python leo wrote: > 你的PythonDelphiVar有了onchange属性了吧? > 调用PYTHON函数可以用DELPHI触发PYTHONEngine来执行字符串或文件,我的做法是把资源读出来,用python引擎执行字符串 > > On 4/14/05, Tom <myata99 at tom.com> wrote: > >>请各位指点,谢谢! >> >>delphi 7 >>python 2.3 >>win98 >>Python for Delphi V3.25 >> >>问题1: >> >>在delphi里面: >>1 创建一个 Form ; >>2 创建一个 TMemo(Memo1) 来容纳 python code; >>3 创建一个 TPythonInputOutput (PythonInputOutput1) ; >>4 创建一个 TPythonEngine (PythonEngine1) ; >>5 创建一个 PythonDelphiVar components ,命名为 bx. 设置 VarName 属性 >>和name属性相同; >>6 把TPythonEngine的IO属性连接到TPythonInputOutput; >>7 创建一个 TButton (Button1) ; >>8 在Memo1中写入python代码 (即设置其lines属性): >> >> def ax(m,n): >> y=10 >> bx.value=y+m+n >> ... >> >>现在,点击Button1, 怎样调用python代码中的函数ax,传递参数(比如 m=33 and >>n=25), 取得 bx.ValueAsString ; >> >>Delphi Code: >> >>--------------------------- >> >>unit Unit1; >> >>interface >> >>uses >> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, >>Forms, >> Dialogs, PythonEngine, StdCtrls; >> >>type >> TForm1 = class(TForm) >> Memo1: TMemo; >> Button1: TButton; >> PythonEngine1: TPythonEngine; >> bx: TPythonDelphiVar; >> PythonInputOutput1: TPythonInputOutput; >> procedure Button1Click(Sender: TObject); >> private >> { Private declarations } >> public >> { Public declarations } >> end; >> >>var >> Form1: TForm1; >> >>implementation >> >>{$R *.dfm} >> >>procedure TForm1.Button1Click(Sender: TObject); >>begin >> ///////////////////////////////////////////////// >> // // >> // How to call the funtion ax passing the // >> // arguments(such as m=33 and n=25), and // >> // get bx.ValueAsString ?? // >> >> // // >> ///////////////////////////////////////////////// >> >> showmessage( bx.ValueAsString ); >> >>end; >> >>end. >> >>------------------------------- >> >>问题2: >> >>还有,如果把python代码保存为一个单独的文件,在delphi中调用该文件,并调用 >>其中的函数,我经过实践,发现python文件只能为.py格式,如果是.pyc,就会失 >>败,我在google搜索,发现有人也遇到这个问题,但没找到解决办法,请教各位有 >>无解决办法?具体的delphi代码该如何写? >> >>谢谢!! >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号