Question Delegates

DriesM

New member
Joined
Jun 6, 2008
Messages
1
Programming Experience
1-3
Hi,

I have search the forum on delgate posts to get an answer to a confusing problem, but so far i was not able to find it, maybe someone else can help me out.
So far i understand the point and usage of delegates in VB.NET and my delegates work fine as long as I declare my delegates as "public" and the target procedure/function as "public shared".
According to this article ( http://vbnotebookfor.net/2007/08/24/introduction-to-vbnet-delegates/ section When and Where To Use a Delegate ) I understand that it is possible to invoke any function procedure private or public from any class with a delegate, even if both are declared as private (and that for me was the big advantage of delegates, accessing private and public functions / procedures form various classes without instantiating these classes as objects.), but i can't bring it to work. If every time i want to use a delegate, and therefore have to declare the target functions and procedures as public shared I can just use the class members without instantiating the class and.
Does someone know how private or public delegates can access private members from other classes without creating an object of the class?

Thanks,

Kind regards
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,583
Location
Norway
Programming Experience
10+
You are confusing two different things. Delegates are pointers to methods. A shared member of a class must be independent of any instance member of the class, an instance member require an instance of a class. So the delegate may point to a shared method of a class without an instance, or an instance method with a instance.

We don't know what you are trying to do, but in most cases events are used for multicast delegation. Then as article mention you have need of delegate when a method must be invoked on other thread, or as method parameters where behaviour is user defined by the assigned user method.
 
Top Bottom