Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass a callback function from Pascal as a parameter to a Python function? #45

Open
heimo88 opened this issue May 31, 2023 · 1 comment

Comments

@heimo88
Copy link

heimo88 commented May 31, 2023

Hi,
I have tried several approaches to pass a Delphi callback function to be used by Python, but the functions are not being called.
`
procedure CallbackFunc(args: Variant);
begin
Form1.Memo1.Lines.add('111');
// ...
end;

callback:=PythonEngine1.PyCFunction_NewEx(@CallbackFunc, nil,nil);
PythonEngine1.Py_INCREF(callback);

//client.subscribe_whole_quote(NewPythonDict,TVarProc(cb));
//codelist := VarPythonCreate(['SZ']);
codelist := PythonEngine1.PyList_New(1);
PythonEngine1.PyList_SetItem(codelist, 0, PythonEngine1.PyUnicode_FromString('110072.SH'));

argsTuple := PythonEngine1.PyTuple_New(2);
PythonEngine1.PyTuple_SetItem(argsTuple, 0, codelist);
PythonEngine1.PyTuple_SetItem(argsTuple, 1, callback);
ss :=GetPythonEngine.EvalPyFunction(ExtractPythonObjectFrom( client.subscribe_whole_quote ), argsTuple); `

in the code subscribe_whole_quote is a python function have 2 parms, 1st is a list, and 2d is the callback function, when I called the subscribe_whole_quote it returned success, but never call the callback function.

@heimo88
Copy link
Author

heimo88 commented May 31, 2023

the subscribe_whole_quote is in a pyd file. client := Import('pythonclient.pyd');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant