Results 1 to 7 of 7

Thread: AddressOf - With a Variable?

Threaded View

  1. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: AddressOf - With a Variable?

    Vektor

    That is not quite what I'm after. Say I had several functions that had the same interface as the delegate. How could I specify the function name as a string variable?

    Perhaps if I gave a psudo-code example to explain what I mean:
    VB Code:
    1. Private Delegate Sub MyDelete(ByVal showText As String)
    2.  
    3.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.       Dim strFunctionName as String
    5.       Dim oDelegateObject As MyDelete
    6.      
    7.       strFunctionName = "MyDelegateCallback"
    8.  
    9.       oDelegateObject = New MyDelete(AddressOf strFunctionName)
    10.  
    11.       oDelegateObject.Invoke("I am using a delegate!")
    12.    End Sub
    13.  
    14.    Private Sub MyDelegateCallback(ByVal showText As String)
    15.       MessageBox.Show(showText.Trim())
    16.    End Sub

    NOTE: I need the function name to be a string variable because I will be getting it from an XML file.
    Last edited by simonm; Mar 17th, 2006 at 03:47 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

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