How to get handle of object that implimented my class

R

Richard

See '###PROBLEM### below


Public Class Form1

Public Interface INotify
Function GetHandle() As System.IntPtr 'Not sure if I should do
this because it
'requires the client to remember to put the code
'in GetHandle and to call IsHandleCreated!

Sub NotifyClient(ByVal Text As String) 'For example
End Interface


Private m_Notify() as INotify

Public Sub Subscribe(TheForm As INotify)
'Adds TheForm to the m_Notify array
End Sub

Private Sub tmrNotify_OnTimer(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles tmrNotify.Tick
'Loops through all objects in m_Notify and calls the NotifyClient
function.

'### PROBLEM ###
'The m_Clients(n).NotifyClient(text) function will be called even if
the client no longer exists. I cannot figure out how to get the handle
of the form that implimented INotify. I can only guess that I have to
use the implimented GetHandle function to check.. but it requires the
client to have the proper code.


End Sub

End Class




Public Class Form2

'Do I really have to do this?
Public Function GetHandle() As System.IntPtr Implements
INotify.GetHandle
If Me.IsHandleCreated() Then
Return Me.Handle
Else
Return 0
End If
End Function


Public Sub NotifyClient(ByVal Text As String) Impliments
INotify.NotifyClient
'
End Sub


End Class


Thanks in advance
 
P

PlatinumBay

Richard,

You can use reflection (GetCallingAssembly) if the calling assembly is .NET.

Otherwise, you may want to add a parameter to pass in a delegate back to the
calling class.


Hope this helps,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top