delegate = WeakAddressOf methodName
The method to which you want a pointer.
It can only be used with instance methods of classes, not with shared methods and global methods from modules (use AddressOf for those).
If the delegate method is invoked after the object has been destroyed, an exception will be raised.
WeakAddressOf and AddressOf are operators, not functions, and cannot be used with parentheses. For example, WeakAddressOf(someMethod) leads to an error. Use WeakAddressOf someMethod instead.
This example lets you handle the Timer.Action event without creating a Timer subclass. Start by adding a property to the layout:
MyTimer As Timer
Next, add a ProgressBar to the layout. The Timer will update the ProgressBar.
In the Opening event handler of the layout, instantiate the Timer and indicate that its Action event handler should be handled by a method, TimerAction, that you will add to the layout:
MyTimer = New Timer MyTimer.Period = 1000 MyTimer.Mode = Timer.Modes.Multiple AddHandler MyTimer.Action, WeakAddressOf TimerAction
Now add the TimerAction method to the layout:
Sub TimerAction(sender As Timer) If ProgressBar1.Value < ProgressBar1.MaximumValue Then ProgressBar1.Value = ProgressBar1.Value + 1 Else ' Stop Timer and Remove the handler sender.Mode = Timer.Mode.Off RemoveHandler MyTimer.Action, WeakAddressOf TimerAction End If End Sub
All project types on all supported operating systems.