When does a closed form go to Nothing?

  • Thread starter Thread starter Dean Slindee
  • Start date Start date
D

Dean Slindee

When launching another form from the current form, I use the code below to
determine if the form to be launched is already active and showing. If
form = Nothing, then I instantiate it, otherwise I just set it's properties
and refresh the form.

Problem is: when the form already been shown and closed using it's X button
(sending the form thru it's Closing and Disposed events), and then an
attempt is made to reinstantiate it again, the form is NOT Nothing, and
falls into the Else clause below. This generates an error message"

"Cannot access a disposed objected named "frmRecord". Object name:
"frmRecord".

Is this a case of slow garbage collection, and/or is there a way to set a
form to Nothing in the form's Closing or Disposed events?

If frmRecord Is Nothing Then
frmRecord = New frmRecord(intFormatID, intRecordID, FormMode.Edit)

frmRecord.Show()

Else

frmRecord.Mode = FormMode.Edit

frmRecord.RecordID = intRecordID

frmRecord.FormPaint(intRecordID)

frmRecord.Show()

End If



Thanks,

Dean Slindee
 
Dean Slindee said:
When launching another form from the current form, I use the code
below to determine if the form to be launched is already active and
showing. If form = Nothing, then I instantiate it, otherwise I just
set it's properties and refresh the form.

Problem is: when the form already been shown and closed using it's X
button (sending the form thru it's Closing and Disposed events), and
then an attempt is made to reinstantiate it again, the form is NOT
Nothing, and falls into the Else clause below. This generates an
error message"

"Cannot access a disposed objected named "frmRecord". Object
name: "frmRecord".

Is this a case of slow garbage collection, and/or is there a way to
set a form to Nothing in the form's Closing or Disposed events?

Handle the other Form's closed event, and in the event handler, set the
variable = Nothing.

Or:
If frmRecord Is Nothing OrElse frmRecord.IsDisposed Then
frmRecord = New frmRecord(intFormatID, intRecordID, FormMode.Edit)
Else
frmRecord.Mode = FormMode.Edit
frmRecord.RecordID = intRecordID
frmRecord.FormPaint(intRecordID)
End If

frmRecord.Show()
frmRecord.activate


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
this isn't related to the actuall question - however, when I was looking for
isdisposed, it wouldn't show up in the intellisense neither for the form nor
for an object of type 'Control'. ofocurse, it shows up in the object browser
for the Control. am i missing something here?
 
ISK said:
this isn't related to the actuall question - however, when I was
looking for isdisposed, it wouldn't show up in the intellisense
neither for the form nor for an object of type 'Control'. ofocurse,
it shows up in the object browser for the Control. am i missing
something here?

Menu Tools -> Options: Text-Editor -> Basic -> General: uncheck "Hide
advanced members"


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top