You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling from a Delphi client (or MFC C++ client), parameter-less COM method would give "TypeError: xxxxx takes 1 positional argument but 2 were given"
This is because:
When calling from a Delphi client while the target Python method has NO argument (i.e., taking only "self"), arg[0] will be set by Delphi a value of 0x8002000C. This makes args non-empty.
When calling from a C++ MFC/COM client while the target Python method has NO argument (i.e., talking only "self"), arg[0] will be set a value of "None". This makes args non-empty.
The following code would be a "protection" for parameter-less Python COM method.
import inspect
argspec = inspect.getfullargspec(func).args
if len(argspec) == 1 and argspec[0] == "self":
return func()
else:
return func(*args)
The Python COM server is defined in "MyCOMServer.py" file, including with the Delphi project files. Register the COM server first.
Compile and run Delphi, click the "Test Python COM" button
The text was updated successfully, but these errors were encountered:
wxinix
changed the title
Parameterless COM method would give "TypeError: xxxxx takes 1 positional argument but 2 were given", for Delphi and MFC COM client.
Parameter-less COM method would give "TypeError: x.y takes 1 positional argument but 2 were given", for Delphi and MFC COM clients.
Apr 17, 2023
0x8002000C == DISP_E_UNKNOWNLCID - so it sounds like something else is is going wrong with the arg passing. I don't have delphi - is this possible to repro anywhere else? I'm a bit reluctant to take a hack to work around one environment I can't test until I'm very sure it isn't going to break any other environment where things work perfectly well.
I believe the bug is really Delphi's, and should be resolved on Delphi side. I am going close this issue. How can I withdraw the PR, or you can feel free to reject it.
Thank you for your great efforts on pywin32. The more I look into its source code, the more I feel awe about it. COM still alive!
When calling from a Delphi client (or MFC C++ client), parameter-less COM method would give "TypeError: xxxxx takes 1 positional argument but 2 were given"
This is because:
When calling from a Delphi client while the target Python method has NO argument (i.e., taking only "self"), arg[0] will be set by Delphi a value of 0x8002000C. This makes args non-empty.
When calling from a C++ MFC/COM client while the target Python method has NO argument (i.e., talking only "self"), arg[0] will be set a value of "None". This makes args non-empty.
The following code would be a "protection" for parameter-less Python COM method.
Here is a sample Delphi project for replicating the issue. https://github.com/wxinix/Python-COM-Samples/blob/main/Delphi/PythonComDelphiTest.7z
The text was updated successfully, but these errors were encountered: