Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Nov 2001
    Location
    Calgary, AB Canada
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newbie Delegates question (VB NET)

    I used to use vb quite a bit during release 3, but have not used it seriously for quite some time. I am now trying to get back into it, and the whole concept of Delegates is proving quiet difficult for me.

    Can someone please explain what these are, and how they work ? I have a good handle on classes, but delegates are a complete mystery to me at the moment.

  2. #2
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Newbie Delegates question (VB NET)

    I too am new to .Net but have used a much newer version of VB and VBA than your last experience. Delegates have nothing to do with classes, they are the way in which you can write your own events (code which gets triggered to run on some action such as a key press or a Windows message).

    Stolen from the book "Coding Techniques for MS VB.Net" by Connell:
    "A delegate formalizes the process of declaring a procedure that will respond to an event. A delegate is used to communicate the message (of the event being triggered) between the source and the listener (your code). Another powerful feature of delegates is multicast functionality, which means that a single sender can be dispatched to several receivers, acting as a one-to-many relationship."

    An example from a book I have shows a program that monitors changes in certain files on the disk. So if a given file/s has changed (been edited, or a new file of a certain type has been created/written to the disk) it triggers an event which your code then responds to. So if you wrote code that needs to run when a file of type .txt is created in directory C:MyFiles then you'd need to create a 'delegate' to monitor that action.
    So a delegate lets you get notified when non-standard events occur (events that aren't part of the regular Framework such as button clicks in a Windows form app).

    I haven't used them myself but the book "Coding Techniques for MS VB.Net" by Connell has been very good in giving me a great start at .Net (even if you're using C#, it doesn't matter, .Net is the same just minor syntax differences for another language). I've read every page of that book and have manually entred most of the code and that's made a big impact on my understanding of this new development environment.

    HTH, Deb

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Newbie Delegates question (VB NET)

    I'm getting quite mutlilingual myself, but I must take a bit of an exception to your:

    >>minor syntax differences

    VB.Net and C# syntax differences are minor if C and QBASIC syntax differences are minor.

    Maybe if I could remember the semicolon and all the previously unecessary parenthesis and braces
    the "minor" would not seem so "major".
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Newbie Delegates question (VB NET)

    I guess it depends on your point of reference. I did 8 yrs of C and 3 yrs of C++ before doing any VB or VBA so for me the differences aren't that big of a deal. I found it more annoying going from C++ to VBA and cursed the syntax for a little while. At least the keywords are the same and for the most part the same functionality is offered and that's what important not whether or not I have to remember to add semicolons or use {} or not. It's an easier leap than VB to Perl.

    Deb <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>

Posting Permissions

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