all groups > vb.net > march 2004 >
vb.net :
CallByName - Referenced by a Variable.
Steve, [quoted text, click to view] > 1. How do I code an ObjectRef so that it can be stored in a variable.
"ObjectRef" is the name of the parameter, the type of the parameter is "Object". Use any Object variable as the parameter. Remember that all types inherit from Object, so you can use any variable as the first parameter. Dim i As Integer = 100 Dim o As Object o = CallByName(i, "ToString", CallType.Method) [quoted text, click to view] > 2. Can I reference methods in a module with a CallByName or similar
I don't see that Modules or Shared methods are supported, as they do not have an instance of an Object associated with them. The ObjectRef parameter is required, you get an exception if you attempt to pass Nothing. This makes sense as I am certain that it is using Reflection to check the object to see if it has the method (without the object it would not know if it had the method or not). Also remember that multiple Modules can have a method with the same name in them. Hope this helps Jay [quoted text, click to view] "runningdog" <runningdog@reply.to.newsgroup> wrote in message news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... > I'm having difficulty with CallByName. > Syntax ask for an ObjectRef as Object. > > 1. How do I code an ObjectRef so that it can be stored in a variable. > 2. Can I reference methods in a module with a CallByName or similar > > > Thanks in advance > Steve >
Steve, [quoted text, click to view] > RE: 1. I think you will find that while your analysis is ok, the example > will fail looking for Object 100. > Dim o As Object > o = MyObject ' Declared elsewhere in the solution > CallByName(o, "MyMethod", CallType.Method)
I'm not following you? MyObject needs to be an object of a type (class or structure) that has a method (sub or function) called MyMethod, if it doesn't it will fail. Also you will need to be certain to match the number & types of the parameters. Or is your second post saying you figured the above out? Hope this helps Jay [quoted text, click to view] "runningdog" <runningdog@reply.to.newsgroup> wrote in message news:40570afc$0$65562$c30e37c6@lon-reader.news.telstra.net... > > > Jay B. Harlow [MVP - Outlook] wrote: > > > Steve, > > > >>1. How do I code an ObjectRef so that it can be stored in a variable. > > > > "ObjectRef" is the name of the parameter, the type of the parameter is > > "Object". Use any Object variable as the parameter. Remember that all types > > inherit from Object, so you can use any variable as the first parameter. > > > > Dim i As Integer = 100 > > Dim o As Object > > o = CallByName(i, "ToString", CallType.Method) > > > > > >>2. Can I reference methods in a module with a CallByName or similar > > > > I don't see that Modules or Shared methods are supported, as they do not > > have an instance of an Object associated with them. The ObjectRef parameter > > is required, you get an exception if you attempt to pass Nothing. This makes > > sense as I am certain that it is using Reflection to check the object to see > > if it has the method (without the object it would not know if it had the > > method or not). > > > > Also remember that multiple Modules can have a method with the same name in > > them. > > > > Hope this helps > > Jay > > > Thanks I had come to a similar conclusion. Modules just looked like a > convenient container for the project I'm working on, but I class works > nicely to. > > RE: 1. I think you will find that while your analysis is ok, the example > will fail looking for Object 100. > Dim o As Object > o = MyObject ' Declared elsewhere in the solution > CallByName(o, "MyMethod", CallType.Method) > > > "runningdog" <runningdog@reply.to.newsgroup> wrote in message > > news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... > > > >>I'm having difficulty with CallByName. > >>Syntax ask for an ObjectRef as Object. > >> > >>1. How do I code an ObjectRef so that it can be stored in a variable. > >>2. Can I reference methods in a module with a CallByName or similar > >> > >> > >>Thanks in advance > >>Steve > >> > > > > > > >
Steve, Rather then using CallByName, which is a form of Late Binding, consider using an Interface which is a form of Early Binding. Early Binding will perform better then Late Binding. [quoted text, click to view] > Project A.
Public Interface IMyObject Sub MyMethod End Interface Public o As IMyObject [quoted text, click to view] > ...
o.MyMethod() [quoted text, click to view] > Project B. > A.o = MyObject ' new Whatever() > ...
Public Class Whatever Implements A.IMyObject [quoted text, click to view] > Public Sub MyMethod Implements A.IMyObject.MyMethod > ... > End Sub
Of course knowing how CallByName is also helpful, especially when the method name varies and may be coming from a database or XML file... Hope this helps Jay [quoted text, click to view] "runningdog" <runningdog@reply.to.newsgroup> wrote in message news:405772de$0$65559$c30e37c6@lon-reader.news.telstra.net... > > Jay B. Harlow [MVP - Outlook] wrote: > > > Steve, > > > >>RE: 1. I think you will find that while your analysis is ok, the example > >>will fail looking for Object 100. > >> Dim o As Object > >> o = MyObject ' Declared elsewhere in the solution > >> CallByName(o, "MyMethod", CallType.Method) > > > > I'm not following you? > > > > MyObject needs to be an object of a type (class or structure) that has a > > method (sub or function) called MyMethod, if it doesn't it will fail. Also > > you will need to be certain to match the number & types of the parameters. > Myobject is an object with a set of methods declared in another project > that will consume this object that needs to interact with Myobject. The > code looks more like. > > Project A. > Public o As Object > ... > CallByName(o, "MyMethod", CallType.Method) > > Project B. > A.o = MyObject > ... > Public Sub MyMethod > ... > End Sub > > > > Or is your second post saying you figured the above out? > Yes, Thanks for the input. > > > > Hope this helps > > Jay > > > > "runningdog" <runningdog@reply.to.newsgroup> wrote in message > > news:40570afc$0$65562$c30e37c6@lon-reader.news.telstra.net... > > > >> > >>Jay B. Harlow [MVP - Outlook] wrote: > >> > >> > >>>Steve, > >>> > >>> > >>>>1. How do I code an ObjectRef so that it can be stored in a variable. > >>> > >>>"ObjectRef" is the name of the parameter, the type of the parameter is > >>>"Object". Use any Object variable as the parameter. Remember that all > > > > types > > > >>>inherit from Object, so you can use any variable as the first parameter. > >>> > >>> Dim i As Integer = 100 > >>> Dim o As Object > >>> o = CallByName(i, "ToString", CallType.Method) > >>> > >>> > >>> > >>>>2. Can I reference methods in a module with a CallByName or similar > >>> > >>>I don't see that Modules or Shared methods are supported, as they do not > >>>have an instance of an Object associated with them. The ObjectRef > > > > parameter > > > >>>is required, you get an exception if you attempt to pass Nothing. This > > > > makes > > > >>>sense as I am certain that it is using Reflection to check the object to > > > > see > > > >>>if it has the method (without the object it would not know if it had the > >>>method or not). > >>> > >>>Also remember that multiple Modules can have a method with the same name > > > > in > > > >>>them. > >>> > >>>Hope this helps > >>>Jay > >>> > >> > >>Thanks I had come to a similar conclusion. Modules just looked like a > >>convenient container for the project I'm working on, but I class works > >>nicely to. > >> > >>RE: 1. I think you will find that while your analysis is ok, the example > >>will fail looking for Object 100. > >> Dim o As Object > >> o = MyObject ' Declared elsewhere in the solution > >> CallByName(o, "MyMethod", CallType.Method) > >> > >> > >>>"runningdog" <runningdog@reply.to.newsgroup> wrote in message > >>>news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... > >>> > >>> > >>>>I'm having difficulty with CallByName. > >>>>Syntax ask for an ObjectRef as Object. > >>>> > >>>>1. How do I code an ObjectRef so that it can be stored in a variable. > >>>>2. Can I reference methods in a module with a CallByName or similar > >>>> > >>>> > >>>>Thanks in advance > >>>>Steve > >>>> > >>> > >>> > >>> > > > > >
I'm having difficulty with CallByName. Syntax ask for an ObjectRef as Object. 1. How do I code an ObjectRef so that it can be stored in a variable. 2. Can I reference methods in a module with a CallByName or similar Thanks in advance Steve
[quoted text, click to view] runningdog wrote: > I'm having difficulty with CallByName. > Syntax ask for an ObjectRef as Object. > > 1. How do I code an ObjectRef so that it can be stored in a variable.
Got this one working [quoted text, click to view] > 2. Can I reference methods in a module with a CallByName or similar. > > > Thanks in advance > Steve >
[quoted text, click to view] Jay B. Harlow [MVP - Outlook] wrote: > Steve, > >>1. How do I code an ObjectRef so that it can be stored in a variable. > > "ObjectRef" is the name of the parameter, the type of the parameter is > "Object". Use any Object variable as the parameter. Remember that all types > inherit from Object, so you can use any variable as the first parameter. > > Dim i As Integer = 100 > Dim o As Object > o = CallByName(i, "ToString", CallType.Method) > > >>2. Can I reference methods in a module with a CallByName or similar > > I don't see that Modules or Shared methods are supported, as they do not > have an instance of an Object associated with them. The ObjectRef parameter > is required, you get an exception if you attempt to pass Nothing. This makes > sense as I am certain that it is using Reflection to check the object to see > if it has the method (without the object it would not know if it had the > method or not). > > Also remember that multiple Modules can have a method with the same name in > them. > > Hope this helps > Jay >
Thanks I had come to a similar conclusion. Modules just looked like a convenient container for the project I'm working on, but I class works nicely to. RE: 1. I think you will find that while your analysis is ok, the example will fail looking for Object 100. Dim o As Object o = MyObject ' Declared elsewhere in the solution CallByName(o, "MyMethod", CallType.Method) [quoted text, click to view] > "runningdog" <runningdog@reply.to.newsgroup> wrote in message > news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... > >>I'm having difficulty with CallByName. >>Syntax ask for an ObjectRef as Object. >> >>1. How do I code an ObjectRef so that it can be stored in a variable. >>2. Can I reference methods in a module with a CallByName or similar >> >> >>Thanks in advance >>Steve >> > > >
[quoted text, click to view] Jay B. Harlow [MVP - Outlook] wrote: > Steve, > >>RE: 1. I think you will find that while your analysis is ok, the example >>will fail looking for Object 100. >> Dim o As Object >> o = MyObject ' Declared elsewhere in the solution >> CallByName(o, "MyMethod", CallType.Method) > > I'm not following you? > > MyObject needs to be an object of a type (class or structure) that has a > method (sub or function) called MyMethod, if it doesn't it will fail. Also > you will need to be certain to match the number & types of the parameters.
Myobject is an object with a set of methods declared in another project that will consume this object that needs to interact with Myobject. The code looks more like. Project A. Public o As Object ... CallByName(o, "MyMethod", CallType.Method) Project B. A.o = MyObject ... Public Sub MyMethod ... End Sub [quoted text, click to view] > > Or is your second post saying you figured the above out? Yes, Thanks for the input. > > Hope this helps > Jay > > "runningdog" <runningdog@reply.to.newsgroup> wrote in message > news:40570afc$0$65562$c30e37c6@lon-reader.news.telstra.net... > >> >>Jay B. Harlow [MVP - Outlook] wrote: >> >> >>>Steve, >>> >>> >>>>1. How do I code an ObjectRef so that it can be stored in a variable. >>> >>>"ObjectRef" is the name of the parameter, the type of the parameter is >>>"Object". Use any Object variable as the parameter. Remember that all > > types > >>>inherit from Object, so you can use any variable as the first parameter. >>> >>> Dim i As Integer = 100 >>> Dim o As Object >>> o = CallByName(i, "ToString", CallType.Method) >>> >>> >>> >>>>2. Can I reference methods in a module with a CallByName or similar >>> >>>I don't see that Modules or Shared methods are supported, as they do not >>>have an instance of an Object associated with them. The ObjectRef > > parameter > >>>is required, you get an exception if you attempt to pass Nothing. This > > makes > >>>sense as I am certain that it is using Reflection to check the object to > > see > >>>if it has the method (without the object it would not know if it had the >>>method or not). >>> >>>Also remember that multiple Modules can have a method with the same name > > in > >>>them. >>> >>>Hope this helps >>>Jay >>> >> >>Thanks I had come to a similar conclusion. Modules just looked like a >>convenient container for the project I'm working on, but I class works >>nicely to. >> >>RE: 1. I think you will find that while your analysis is ok, the example >>will fail looking for Object 100. >> Dim o As Object >> o = MyObject ' Declared elsewhere in the solution >> CallByName(o, "MyMethod", CallType.Method) >> >> >>>"runningdog" <runningdog@reply.to.newsgroup> wrote in message >>>news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... >>> >>> >>>>I'm having difficulty with CallByName. >>>>Syntax ask for an ObjectRef as Object. >>>> >>>>1. How do I code an ObjectRef so that it can be stored in a variable. >>>>2. Can I reference methods in a module with a CallByName or similar >>>> >>>> >>>>Thanks in advance >>>>Steve >>>> >>> >>> >>> > >
Jay, That is most helpful thanks. I'm very new to VB and this kind of input makes the curve a lot easier. Steve [quoted text, click to view] Jay B. Harlow [MVP - Outlook] wrote: > Steve, > Rather then using CallByName, which is a form of Late Binding, consider > using an Interface which is a form of Early Binding. > > Early Binding will perform better then Late Binding. > > >>Project A. > > Public Interface IMyObject > Sub MyMethod > End Interface > > > Public o As IMyObject > >> ... > > o.MyMethod() > > > >>Project B. >> A.o = MyObject ' new Whatever() >> ... > > Public Class Whatever > Implements A.IMyObject > >> Public Sub MyMethod Implements A.IMyObject.MyMethod >> ... >> End Sub > > > Of course knowing how CallByName is also helpful, especially when the method > name varies and may be coming from a database or XML file... > > Hope this helps > Jay > > > "runningdog" <runningdog@reply.to.newsgroup> wrote in message > news:405772de$0$65559$c30e37c6@lon-reader.news.telstra.net... > >>Jay B. Harlow [MVP - Outlook] wrote: >> >> >>>Steve, >>> >>> >>>>RE: 1. I think you will find that while your analysis is ok, the example >>>>will fail looking for Object 100. >>>> Dim o As Object >>>> o = MyObject ' Declared elsewhere in the solution >>>> CallByName(o, "MyMethod", CallType.Method) >>> >>>I'm not following you? >>> >>>MyObject needs to be an object of a type (class or structure) that has a >>>method (sub or function) called MyMethod, if it doesn't it will fail. > > Also > >>>you will need to be certain to match the number & types of the > > parameters. > >>Myobject is an object with a set of methods declared in another project >>that will consume this object that needs to interact with Myobject. The >>code looks more like. >> >>Project A. >> Public o As Object >> ... >> CallByName(o, "MyMethod", CallType.Method) >> >>Project B. >> A.o = MyObject >> ... >> Public Sub MyMethod >> ... >> End Sub >> >>>Or is your second post saying you figured the above out? >> >>Yes, Thanks for the input. >> >>>Hope this helps >>>Jay >>> >>>"runningdog" <runningdog@reply.to.newsgroup> wrote in message >>>news:40570afc$0$65562$c30e37c6@lon-reader.news.telstra.net... >>> >>> >>>>Jay B. Harlow [MVP - Outlook] wrote: >>>> >>>> >>>> >>>>>Steve, >>>>> >>>>> >>>>> >>>>>>1. How do I code an ObjectRef so that it can be stored in a variable. >>>>> >>>>>"ObjectRef" is the name of the parameter, the type of the parameter is >>>>>"Object". Use any Object variable as the parameter. Remember that all >>> >>>types >>> >>> >>>>>inherit from Object, so you can use any variable as the first > > parameter. > >>>>> Dim i As Integer = 100 >>>>> Dim o As Object >>>>> o = CallByName(i, "ToString", CallType.Method) >>>>> >>>>> >>>>> >>>>> >>>>>>2. Can I reference methods in a module with a CallByName or similar >>>>> >>>>>I don't see that Modules or Shared methods are supported, as they do > > not > >>>>>have an instance of an Object associated with them. The ObjectRef >>> >>>parameter >>> >>> >>>>>is required, you get an exception if you attempt to pass Nothing. This >>> >>>makes >>> >>> >>>>>sense as I am certain that it is using Reflection to check the object > > to > >>>see >>> >>> >>>>>if it has the method (without the object it would not know if it had > > the > >>>>>method or not). >>>>> >>>>>Also remember that multiple Modules can have a method with the same > > name > >>>in >>> >>> >>>>>them. >>>>> >>>>>Hope this helps >>>>>Jay >>>>> >>>> >>>>Thanks I had come to a similar conclusion. Modules just looked like a >>>>convenient container for the project I'm working on, but I class works >>>>nicely to. >>>> >>>>RE: 1. I think you will find that while your analysis is ok, the example >>>>will fail looking for Object 100. >>>> Dim o As Object >>>> o = MyObject ' Declared elsewhere in the solution >>>> CallByName(o, "MyMethod", CallType.Method) >>>> >>>> >>>> >>>>>"runningdog" <runningdog@reply.to.newsgroup> wrote in message >>>>>news:4056f8b2$0$65568$c30e37c6@lon-reader.news.telstra.net... >>>>> >>>>> >>>>> >>>>>>I'm having difficulty with CallByName. >>>>>>Syntax ask for an ObjectRef as Object. >>>>>> >>>>>>1. How do I code an ObjectRef so that it can be stored in a variable. >>>>>>2. Can I reference methods in a module with a CallByName or similar >>>>>> >>>>>> >>>>>>Thanks in advance >>>>>>Steve >>>>>> >>>>> >>>>> >>>>> >>> > >
Don't see what you're looking for? Try a search.
|
|
|