D
Dean Slindee
This code was originally written in VS2003, when you needed to keep manual
references (hashtable) of form references in order to be able to refer to
another form already in memory.
Anyway, the question setup go like this:
1.. Assume that there is a hashtable that contains one reference to each
form loaded thus far.
Loaded like this in the form_Load event:
Private Sub frmFacilityHost_Load(.
Dim wr As WeakReference = New WeakReference(Me, False)
If Not hashForm.Contains(Me.Name) Then
hashForm.Add(Me.Name, wr)
End If
2.. Now, in another form, to get a reference to the above form, I use this
code:
Try
Dim wr As WeakReference
Dim frmFacilityHost As frmFacilityHost
wr = DirectCast(hashForm(cfrmFacilityHost), WeakReference)
frmFacilityHost = DirectCast(wr.Target, frmFacilityHost)
Call frmFacilityHost.FormPaint(CType(s1, String))
Catch exc As InvalidCastException
Call WinExcept.ExceptionHandler.Exception(Me.Name, exc)
Finally
'frmFacilityHost = Nothing
End Try
3.. QUESTION: I am assuming that the above frmFacilityHost is one and the
same area of memory as the form in #1. Is this correct? I further assume
that the commented line assigning frmFacilityHost = Nothing is not needed
and would cause a loss of form.
4.. Is this hashtable approach still needed in VS2005? What would the
replacement code look like?
5.. Should I be setting the wr = Nothing is either of these functions?
Thanks,
Dean S
references (hashtable) of form references in order to be able to refer to
another form already in memory.
Anyway, the question setup go like this:
1.. Assume that there is a hashtable that contains one reference to each
form loaded thus far.
Loaded like this in the form_Load event:
Private Sub frmFacilityHost_Load(.
Dim wr As WeakReference = New WeakReference(Me, False)
If Not hashForm.Contains(Me.Name) Then
hashForm.Add(Me.Name, wr)
End If
2.. Now, in another form, to get a reference to the above form, I use this
code:
Try
Dim wr As WeakReference
Dim frmFacilityHost As frmFacilityHost
wr = DirectCast(hashForm(cfrmFacilityHost), WeakReference)
frmFacilityHost = DirectCast(wr.Target, frmFacilityHost)
Call frmFacilityHost.FormPaint(CType(s1, String))
Catch exc As InvalidCastException
Call WinExcept.ExceptionHandler.Exception(Me.Name, exc)
Finally
'frmFacilityHost = Nothing
End Try
3.. QUESTION: I am assuming that the above frmFacilityHost is one and the
same area of memory as the form in #1. Is this correct? I further assume
that the commented line assigning frmFacilityHost = Nothing is not needed
and would cause a loss of form.
4.. Is this hashtable approach still needed in VS2005? What would the
replacement code look like?
5.. Should I be setting the wr = Nothing is either of these functions?
Thanks,
Dean S