473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get handle of object that implimented my class

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

Jun 4 '07 #1
1 1702
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


"Richard" <so**********@cox.netwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
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

Jun 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only works with a subset of floating point values. In...
7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
0
by: Paul | last post by:
Hi not too familiar with COM but have built .NET applications and added references to assemblies and then implimented the namespace or class in code. Is this the same thing as using COM? thanks....
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
7
by: Shraddha | last post by:
What is exactly a handle to an object????Is it same as reference....
4
by: Donos | last post by:
Hi I have a HANDLE to an Event, like this.. HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL); This is running in one thread in one class. For example we will call that class as "Class A"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.