How to pass "byref" parameters to COM object methods

Paul Moore gustav at morpheus.demon.co.uk
Tue Aug 7 00:28:51 CEST 2001


On Sat, 4 Aug 2001 12:39:44 -0400 (EDT), Bob Kline <bkline at rksystems.com> wrote:

>An example of where such a mechanism is needed is the Execute() method
>of the ADO Connection object.  Microsoft uses the RecordsAffected
>parameter to return the count of rows affected by the operation
>performed.

What happens is that the return value in Python is a tuple made up of the (VB)
return value, followed by the returned values of any "out" or "in out" (ByRef in
VB terms) parameters. As an example,

from win32com.client import Dispatch

def Test():
    Conn = Dispatch("ADODB.Connection")
    Conn.Open("Provider=msdaora;Data Source=test;User ID=scott;Password=tiger")

    # Set RS = Execute(ByVal SQL As String,
    #                  ByRef RecordsAffected As Integer,
    #                  ByVal Options As Integer)
    #
    # Return value is a tuple, first the "official" return value, then
    # any "out" parameters, in order.
    RS, n = Conn.Execute("select * from emp")

    # For a non-recordset-returning execute, there is no "return value", so
    # we just get the RecordsAffected output parameter.
    n = Conn.Execute("update emp set sal = sal")

if __name__ == '__main__':
    Test()

Hope this helps,
Paul.



More information about the Python-list mailing list