Check if Component is not disposed?

I

IdleBrain

Hello:
I have written the following code in the main form close event
procedure:
If Not instfrmMain.rb1 Is Nothing Then instfrmMain.rb1.Checked = True


But I still get an error from the JIT compiler that the rb1 component
does not exist any more..ie. it is disposed..and I am trying to access
its properties.

How can we make sure that the component exists before any of its
property is changed?

Thanks
 
M

Marina Levit [MVP]

Just because a component is disposed, does not meant that the variable that
points to it is Nothing. Disposing a component means calling its Dispose
method - and that just runs some clean up code. It's not magic that sets
everything that ever pointed to that object to point to nothing.

If you want the variable to point to nothing after you dispose the object,
then add a line of code to set it to Nothing.
 
I

IdleBrain

Hai Marina,
I apologize for unable to explain my issue clearly..

I am trying to change the checked property of a radio button on closing
the main form.
But, I get an error from the JIT, sometimes, saying that the radio
button that I am trying to access is disposed.

Is there any method that I can use to check if a component is disposed?
 
G

Guest

Hi,

Why dont you use the closing event instead? The form closing can
be cancel so the control still exist.

Ken
 
I

IdleBrain

Hello Ken,
I tried using Closing() event instead of Closed() but the problem still
exists.
Its hard to check on when JIT would dispose unused components I guess..

Any other suggestions?
 
C

Cor Ligthert [MVP]

IdleBbrain,

Although there is the property control.IsDisposed. I don't understand why
you want to change something in your window while it is closing. The eyes of
humans are fare to slow to see that.

Or do you want to cancel the closing before?

Cor
 
I

IdleBrain

Hello Cor,
Whenever I make changes to the A/D card, I update its GUI part using
subroutines.
When the form is being closed, I want to use the same subroutine to
reset the A/D card voltages too..thats when this problem arises.

Conrol.IsDisposed seems to be working good. I knew something like this
one existed.
I still wonder why the intellisense help does not indicate the
IsDisposed method?

Thank you very much..
 
I

IdleBrain

Hello Cor,
Whenever I make changes to the A/D card, I update its GUI part using
subroutines.
When the form is being closed, I want to use the same subroutine to
reset the A/D card voltages too..thats when this problem arises.

Conrol.IsDisposed seems to be working good. I knew something like this
one existed.
I still wonder why the intellisense help does not indicate the
IsDisposed method?

Thank you very much..
 
C

Cor Ligthert [MVP]

IdleBrain,

I still wonder why the intellisense help does not indicate the
IsDisposed method?

Nobody does that, but it is placed in the complex members of control which
are not standard showed in intellisense. (You can set it in the properties
from the IDE to show it). In VS 2005 it is a tab.

Cor
 

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