Results 1 to 2 of 2

Thread: Trouble with reflection

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Trouble with reflection

    Hi All

    I'm haveing some trouble with reflection :

    Code:
    Dim o As Object = Nothing
    o = Assembly.Load(ay).CreateInstance(fullyQualifiedClassName)
    How can I wire up an event called "Error"? I cant even see an event when looking at "o".
    What am I doing wrong?

    Parksie

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Trouble with reflection

    Of course you can't, because 'o' is type Object. Does the Object class have any events? You're using Reflection, which means discovering types and members at run time. If you create an object by Reflection then you have to access its members by Reflection too. The PropertyInfo class is used to represent properties, the MethodInfo class is used to represent methods and the EventInfo class is used to represent events. You can call GetType on your object and then call GetEvent or GetEvents on that to get one or multiple EventInfo objects. Once you have an EventInfo object, you call its AddEventHandler method to add a handler for that event to your original object. I think that you probably need to do some more general reading on how Reflection works.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width