Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object? 
Author Message
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?

I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 19:56:42 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Hello,

I think I am following you. Where is Description though? Is it a member of one of the collection classes? You need to make sure you are correctly setting the property on the collection's object, not on the collection itself -- can you explain just a little more and I'll do some checking as well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh

I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 20:47:03 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Josh,

             Thanks..... The Description is a property of  an object that
has
been added to the collection.  In my case all objects in the collection are
the exact
same type.   I am writing a dynamic validation function, so as the
validation is called for
a field on the screen, I need to set the object to contain the data from the
text box that
was validated.

             Does this help you.

        Steve


Hello,

I think I am following you. Where is Description though? Is it a member of
one of the collection classes? You need to make sure you are correctly
setting the property on the collection's object, not on the collection
itself -- can you explain just a little more and I'll do some checking as
well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 21:05:54 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Hey Steve,

Check out the PropertyInfo class and SetValue.

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh

Josh,

             Thanks..... The Description is a property of  an object that
has
been added to the collection.  In my case all objects in the collection are
the exact
same type.   I am writing a dynamic validation function, so as the
validation is called for
a field on the screen, I need to set the object to contain the data from the
text box that
was validated.

             Does this help you.

        Steve


Hello,

I think I am following you. Where is Description though? Is it a member of
one of the collection classes? You need to make sure you are correctly
setting the property on the collection's object, not on the collection
itself -- can you explain just a little more and I'll do some checking as
well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 21:27:17 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Josh,

                 Could you be a bit more specific?

            Steve


Hey Steve,

Check out the PropertyInfo class and SetValue.

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


Josh,

             Thanks..... The Description is a property of  an object that
has
been added to the collection.  In my case all objects in the collection are
the exact
same type.   I am writing a dynamic validation function, so as the
validation is called for
a field on the screen, I need to set the object to contain the data from the
text box that
was validated.

             Does this help you.

        Steve


Hello,

I think I am following you. Where is Description though? Is it a member of
one of the collection classes? You need to make sure you are correctly
setting the property on the collection's object, not on the collection
itself -- can you explain just a little more and I'll do some checking as
well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 21:37:06 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Josh,

           Could you be a bit more specific?

steve


Hey Steve,

Check out the PropertyInfo class and SetValue.

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


Josh,

             Thanks..... The Description is a property of  an object that
has
been added to the collection.  In my case all objects in the collection are
the exact
same type.   I am writing a dynamic validation function, so as the
validation is called for
a field on the screen, I need to set the object to contain the data from the
text box that
was validated.

             Does this help you.

        Steve


Hello,

I think I am following you. Where is Description though? Is it a member of
one of the collection classes? You need to make sure you are correctly
setting the property on the collection's object, not on the collection
itself -- can you explain just a little more and I'll do some checking as
well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 21:38:13 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Here's an example:

PropertyInfo pi = myObj.GetProperty("MyProperty");

Then check out the SetValue method. It's all in the .NET docs, I'd give you an example but still am a little unclear as to what you are trying to do :). Hope that helps!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh

Josh,

                 Could you be a bit more specific?

            Steve


Hey Steve,

Check out the PropertyInfo class and SetValue.

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


Josh,

             Thanks..... The Description is a property of  an object that
has
been added to the collection.  In my case all objects in the collection are
the exact
same type.   I am writing a dynamic validation function, so as the
validation is called for
a field on the screen, I need to set the object to contain the data from the
text box that
was validated.

             Does this help you.

        Steve


Hello,

I think I am following you. Where is Description though? Is it a member of
one of the collection classes? You need to make sure you are correctly
setting the property on the collection's object, not on the collection
itself -- can you explain just a little more and I'll do some checking as
well? Thanks!

--

Sincerely,

Josh Mitts

www.treasureonthenet.com/josh


I have an object defined as cFile
This object has 3 variables and defined collection.

The 3 variables and the collection have Public Property implementations

I need to  use InvokeMethod to Set a property on one of the objects within
the collection.

I see documentation on how to set a simple index with InvokeMethod, but  I
can't seem to find an answer to my problem.

ie.

Public Function SetPropertyViaInvokeMethod
Dim objFile as new cfile
Dim nIndex as integer
Dim strName as String

nIndex = 1
strName = "Description"

'This Statement does not currently work.. How can I get the Method defined
by strName (In this case "Description") to execute??
objFile.GetType.InvokeMember(strName, Reflection.BindingFlags.Default Or
Reflection.BindingFlags.SetProperty, Nothing, objFile.Specification, New
Object() {nIndex, sender.text})

End Function

Public Class cFile

    Private   cvarStrOne as String
    Private   cvarStrTwo  as String
    Private   cvarStrThree as String

    Private cvarColSpecification as new collection

End Class

...Public Property One as string...
...Public Property Two as string...
---Public Property Three as string
...Public Property Specification as Collection
        Get
            Return cvarColSpecification



Sat, 27 Mar 2004 21:44:14 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?

Quote:
>              Thanks..... The Description is a property of  an
> object that
> has
> been added to the collection.  In my case all objects in the
> collection are the exact
> same type.   I am writing a dynamic validation function, so as the
> validation is called for
> a field on the screen, I need to set the object to contain the
> data from the text box that
> was validated.

Shouldn't you first get the item within the collection and afterwards
invoke the member of the item and not the Collection?

Armin



Sat, 27 Mar 2004 21:47:08 GMT  
 Help!!!! Trying to Use Invoke Method to set a property of an object in a collection within an object?
Let me see if I can be more clear...

I am writing a generic textbox validation routine that will test each field
on my form
to see if its blank.  I am writing it with my own routine that "handles"
each of the
textboxes "Validation" message.

When my function is called, I use the sender object to identify the sender.
I use the
tag field in each of the textboxes to specify a "class" method name that it
equates to.

When my validation routine is called and the textbox IS NOT BLANK, I then
wish to generically set the property within by class to the value of the
textbox.

I currently use this technique on other forms without issue, however this
form
coincides with a class that contains a collection of objects.

So, my class has 3 variables.  Two of which are Strings and 1 of which is a
collection of objects.  Basically a 1 to many situation.
The form's textboxes can contain a record from any one of the objects in the
collection.

I need to invoke the proper set method based on my knowledge (from the
sender.tag property) to Set the property of the correct object in the
collection based on Sender.Tag.

The following statement works.. but only sets a normal String property in my
class..

strName = Sender.Tag (The name of the method that equates to the text
ield)  - Lets say that the name id "Description"
objMyFileRef.GetType.InvokeMember(strName, Reflection.BindingFlags.Default
Or Reflection.BindingFlags.SetProperty, Nothing, objMyFileRef, New Object()
{sender.text})

The above example will set the value of  objMyFileRef.{strName} =
Sender.text  ..................This is a great generic technique...

However If I am using a collection as my property and I need to set a
property of a specific object in my collection... I can not seem to get it
to work...

So in other words instead of  setting objMyFileRef.Description =
sender.text,  I need to set  objMyFileRef.Specification(x).Description =
sender.text...

I need help with the syntax of the InvokeMember statement to make this
work...

Thanks in advance.  I hope this is clearer.

SLN


Quote:

> >              Thanks..... The Description is a property of  an
> > object that
> > has
> > been added to the collection.  In my case all objects in the
> > collection are the exact
> > same type.   I am writing a dynamic validation function, so as the
> > validation is called for
> > a field on the screen, I need to set the object to contain the
> > data from the text box that
> > was validated.

> Shouldn't you first get the item within the collection and afterwards
> invoke the member of the item and not the Collection?

> Armin



Sun, 28 Mar 2004 02:01:53 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Help: Using InvokeMethod to Set property of object in a collection

2. Using a Set method of a custom Property over the web (NEWBIE)

3. Referrer property not being set properly when using the Navigate method of the WebBrowser control

4. Need help trying to set the AspAllowOutOfProcComponents property.

5. Referrer Property of Document Object not updated using Navigate method of webbrowser controller

6. Should my properties be a method or set by a method

7. Set Default Property of Column Object Using ADOX

8. How to invoke a method in a class module using CALLTHIS()

9. Invoking methods of VB 4 and VB 5 - Controls using the window handle (hwnd)

10. Invoking methods of VB 4 and VB 5 - Controls using the window handle (hwnd)

11. Help: Object Doesn't Support this Property or Method

12. Invoking ActiveX methods using strings

 

 
Powered by phpBB® Forum Software