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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    #1

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

    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 TPythonInputOut put (PythonInputOut put1) ;
    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
    TPythonInputOut put;
    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.ValueAsStrin g ;


    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: TPythonDelphiVa r;
    PythonInputOutp ut1: TPythonInputOut put;
    procedure Button1Click(Se nder: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1C lick(Sender: TObject);
    begin
    /////////////////////////////////////////////////
    // //
    // How to call the funtion ax passing the //
    // arguments(such as m=33 and n=25), and //
    // get bx.ValueAsStrin g ?? //

    // //
    /////////////////////////////////////////////////


    showmessage( bx.ValueAsStrin g );


    end;

    end.



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



    Thank you very much!!








Working...