How to add a method member to a class or object in run-time?

  • Thread starter Thread starter peter
  • Start date Start date
P

peter

In run-time,is there any approach to add or revise the
members,such as method or attribute ,of a class or object?
As for the object of class soapclient30 in MS soap
toolkit, after it executes the mssoapinit method,it will
have some additional methods which have been described in
WSDL file. For an example,if a Web service provides
an "divide" method,the WSDL filename is mycalculator.wsdl:

set soapclient = CreateObject("MSSOAP.SoapClient30")
soapclient.mssoapinit "mycalculator.wsdl", "", "", ""
soapclient.divide 10,5

that is,the soapclient object has the divide method.
how to add the "divide" method for SoapClient30 class
internally?
 
Peter,

peter said:
set soapclient = CreateObject("MSSOAP.SoapClient30")
soapclient.mssoapinit "mycalculator.wsdl", "", "", ""
soapclient.divide 10,5

that is,the soapclient object has the divide method.
how to add the "divide" method for SoapClient30 class
internally?
You simply need to implement IDispatch yourself (don't
mark your interface as nonextensible). Shouldn't be too
hard with help of the Automation helpers.

Eventually, you can also create type information on the
fly and use the CreateStdDispatch, CreateDispTypeInfo,
DispInvoke to implement your interface. That way you
could build your dynamic object with ATLs IDispatchImpl.

-hg
 
Back
Top