By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

How to call a function in embeded python code in delphi?

P: n/a
Tom
delphi 7
python 2.3
win98
Python for Delphi V3.25
In Delphi:
1 Create a new Form ;
2 Drop a TMemo(Memo1) to contain python code;
3 Drop a TPythonInputOutput (PythonInputOutput1) ;
4 Drop a TPythonEngine (PythonEngine1) ;
5 Drag a PythonDelphiVar component and name it bx. Set the VarName
property to the same as its name;
6 Connect the attribute IO of the TPythonEngine to the
TPythonInputOutput;
7 Drop a TButton (Button1) ;
8 Write python code in the Memo1 (set Memo1's property of lines):

def ax(m,n):
y=10
bx.value=y+m+n
...

Now, As click Button1, how to call the funtion ax passing the
arguments(such as m=33 and n=25), and get 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.

-------------------------------

Thank you very much!!


Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.