469,291 Members | 1,783 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

How to test if an object exists?

I know this might seem like a dumb question, but how do you test that an
object exists.

Maybe i should explain a little.

I have a variable that points to an object. Now if that oject is released,
how can i test my variable to see if the object it was pointing at, still
exists?

Please help!!
Nov 21 '05 #1
6 14941
Hi Darren!

"Darren Linsley" schrieb
I know this might seem like a dumb question, but how do you test that an
object exists.

Maybe i should explain a little.

I have a variable that points to an object. Now if that oject is
released,
how can i test my variable to see if the object it was pointing at, still
exists?

Please help!!


If Not myVariable Is Nothing then
.....

Cheers

Arne Janning
Nov 21 '05 #2
I tried that.

The variable is referencing another form.

I am trying to test to see if the form is closed, and if so, re-instanciate
it, prior to performing some actions.

When i test for Nothing once the form has been closed down, it returns
false, indicating the variable reference is still pointing at something. If
i try to reference a property of the form i get an objectdisposedexception.

Any other suggestions??


"Arne Janning" <sp*****************@msn.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Hi Darren!

"Darren Linsley" schrieb
I know this might seem like a dumb question, but how do you test that an
object exists.

Maybe i should explain a little.

I have a variable that points to an object. Now if that oject is
released,
how can i test my variable to see if the object it was pointing at, still exists?

Please help!!


If Not myVariable Is Nothing then
....

Cheers

Arne Janning

Nov 21 '05 #3
On 2004-10-15, Darren Linsley <da************@csiro.au> wrote:
I tried that.

The variable is referencing another form.

I am trying to test to see if the form is closed, and if so, re-instanciate
it, prior to performing some actions.

When i test for Nothing once the form has been closed down, it returns
false, indicating the variable reference is still pointing at something. If
i try to reference a property of the form i get an objectdisposedexception.

Any other suggestions??


Hook the other forms close event, so that when it closes down you can
set your reference to Nothing, then when you do the test - you'll know
it shutdown...

Just a thought.
--
Tom Shelton [MVP]
Nov 21 '05 #4
"Darren Linsley" <da************@csiro.au> schrieb:
I know this might seem like a dumb question, but how do you
test that an object exists.

Maybe i should explain a little.

I have a variable that points to an object. Now if that oject is
released,
how can i test my variable to see if the object it was pointing at, still
exists?


You can check the object's 'IsDisposed' property (for a form, for example).
It's set to 'True' if the object is disposed. Before doing that, compare
the object reference to 'Nothing' ('If o Is Nothing Then...').

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #5
Herfried,

The disposed does not set it to nothing, my expirience with Tom's solution
was strange enough when it was a form better. Although I do not find it nice
so I do not use it and go around it.

Cor
Nov 21 '05 #6
"Cor Ligthert" <no************@planet.nl> schrieb:
The disposed does not set it to nothing


That's true, but you need to check if you ever assigned an instance to the
variable...

But I prefer a solution using a 'Closed' handler or a Singleton too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Squid Seven | last post: by
23 posts views Thread by Randell D. | last post: by
3 posts views Thread by Gareth Tonnessen | last post: by
9 posts views Thread by Chris Ashley | last post: by
4 posts views Thread by Mark Berry | last post: by
2 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.