Please, someone tell me what's going wrong here. ;>
Jason Maskell
backov at nospam.csolve.net
Tue Jan 11 14:32:54 EST 2000
I posted a while back on embedding, and after scouring deja and reading the
demos, I can't even get this simple example to work. It's essentially a C++
Builder'ized version of the simple embedding demo.. PyRun_SimpleString
returns -1 and foo is never executed.
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void initxyzzy(); /* Forward */
/* A static module */
static PyObject * xyzzy_foo(PyObject *self, PyObject *args)
{
Form1->Memo1->Lines->Add("Blah");
return PyInt_FromLong(42L);
}
static PyMethodDef xyzzy_methods[] = {
{"foo", xyzzy_foo, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
void initxyzzy()
{
PyImport_AddModule("xyzzy");
Py_InitModule("xyzzy", xyzzy_methods);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int a;
Py_SetProgramName(Application->ExeName.c_str());
Py_Initialize();
initxyzzy();
a=PyRun_SimpleString("xyzzy.foo()");
Py_Finalize();
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Py_Finalize();
}
More information about the Python-list
mailing list