Dynamic discovery of delegates

N

Nate

Help please, I need a genius!!!

[I'm using VB.NET 2003]

I have an application that loads assemblies at runtime. These assemblies
have many classes (objects) and some do have several delegates. I want to be
able to discover a delegate on an object, and to be able to programmatically
assign it to a callback address.

In my app, I have an object with delegate defined as follows:

public delegate StringChanged(strNewValue as string)
private myStringChangedDelegate as StringChanged

I then have a method to assign a callback to this delegate, such as:

public sub AddListenerToStringChanged(callback as StringChanged)
myStringChangedDelegate = .... ' you know the drill here...
end sub


The thing is, I can (at runtime) detect the above procedure, but I want I
want to do is to programmatically assign a callback address to this...
something along the lines of:

myObject.AddListenerToStringChanged(addressof obj2.StringChangedListener)


I am guessing that I need to use some kind of "MethodInvoke" or something?
but it's the "Addressof" operator that gets me... I just can't find the
information or the syntax that the compiler will accept.

In summary, my question is:
How do I invoke a method which requires an Addressof operator?

Any help would be truly appreciated. Thanks.
 
M

Mattias Sjögren

If you want to dynamically create a delegate of a type that's unknown
at compile time, use System.Delegate.CreateDelegate().



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top