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

T

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top