Delegates

Luc

Well-known member
Joined
Nov 29, 2005
Messages
59
Programming Experience
1-3
Can someone tell me what i'm doing wrong? I made a new project to practice delegates and i keep getting a nullrefrence error on my
VB.NET:
DLGtekst.Invoke(value)

here is the full code, it doesnt do annything usefull, i was just running some tests.

VB.NET:
Public Class Form1
      Dim t As New test
      Dim x As Integer = 0
   
      Private Sub test_invokes()
          t.tekstchange(New test.tekst(AddressOf TextBox1_tekst))
      End Sub
   
      Private Sub Textbox1_tekst(ByVal aantal As Integer)
          TextBox1.Text = "the text has been delegated" & CStr(aantal) & "times"
   
      End Sub
   
   
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Timer1.Enabled = True
      End Sub
   
      Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
          x += 1
          t.aantal = x
      End Sub
  End Class
   
  Public Class test
      Public Delegate Sub tekst(ByVal aantal As Integer)
      Public DLGtekst As tekst
   
      Dim prop_aantal%
   
      Public Sub tekstchange(ByVal value As tekst)
          DLGtekst = value
      End Sub
   
      Public Property aantal() As Integer
          Get
              Return prop_aantal
          End Get
          Set(ByVal value As Integer)
              DLGtekst.Invoke(value)
          End Set
      End Property
  End Class
[FONT=&quot][/FONT]
 
Look to me like you are trying to invoke a delegate inside a class without providing it a function or sub to point to. You have Created your delegate in form1 and pointed it to a sub. But in the class test you are trying to invoke this delegate, but inside the test class it doesn't point to anything.
 
Back
Top