Results 1 to 10 of 10

Thread: [RESOLVED] Type of argument for .Invoke()

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Resolved [RESOLVED] Type of argument for .Invoke()

    Hi folks

    The MDSN page for the Control.Invoke method specifies:

    Control.Invoke Method (Delegate)

    Now I was given in my admittedly limited knowledge to understand that a delegate is just a variable that holds a reference to a function or sub and using a lamda in place ends up passing the same thing when used as a parameter; a reference to a function. (I think of this as similar to passing function pointers in C and a lambda parameter just passes a pointer for a function that's written as an argument)

    This could be where the following confusion stems from I guess but here goes:

    The argument is asked for as a delegate. Using 'SomeControl.Invoke(Sub() somesub(someargs))' works fine. seems to me that's because the argument is a lambda that is a Sub that calls some other sub.
    Yet trying trying to use a Function lambda or a multi-line lambda does not work because (and here's the screen head-butting bit) "the expression does not produce a value"
    ...
    But a lamda produces a value surely, the reference to the anonymous function?
    And if not then how did the original single line Sub lambda work? If lambdas don't fulfil this requirement then how can any form of them work at all? Seems like it is supposed to take delegates but only works for particular types of them or when they're declared in particular ways??

    Anyway what I'd like to end up with is being able to go:

    vb Code:
    1. SomeControl.Invoke(Sub()
    2.     Foo()
    3.     If (Something) then
    4.         Bar()
    5.     End If
    6. End Sub)

    Instead of

    vb Code:
    1. Private Sub StupidHelperSub()
    2.     Bar()
    3.     If (something) Then
    4.         Foo()
    5.     End If
    6. End sub
    7.  
    8. ...
    9.  
    10. SomeControl.Invoke(Sub() StupidHelperSub())
    Last edited by wolf99; Dec 11th, 2015 at 12:06 PM.
    Thanks

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