For the following code, the method "GetPerson" has no explicit argument (except 
self).

class MyCOMObject:
    _public_methods_ = ["GetPerson"]
    #_reg_clsid_ = '{44ee76c7-1290-4ea6-8189-00d5d7cd712a}'
    #_reg_desc_ = "My COM server"
    #_reg_progid_ = "MyCOMObject"

    def get_person(self):
        person = Person("haha", 45)
        wrapped = win32com.server.util.wrap(person, useDispatcher = 
my_dispatcher)
        return wrapped


When calling from VBA, like below , it works fine.
    Set o = CreateObject("MyCOMObject")
    Set p = o.get_person()

However, when calling from C++, or Delphi, the following error will be thrown:
"TypeError: MyCOMObject.get_person() takes 1 positional argument but 2 were 
given"

Delphi code:

procedure TForm1.Button1Click(Sender: TObject);
var
  o: OleVariant;
  p: OleVariant;
begin
  o := CreateOleObject('MyCOMObject');
  p := o.get_person(); // error will be thrown
  s := p.name;
  age := p.age;
  ShowMessage(s);
end;

The fix is to change Line 639 of policy.py to the following:


                 if len(args) == 1 and (args[0] == -2147352572 or args[0] == 
None):
                 return func()
                 else:
                 return func(*args)
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to