By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

How to test if an object exists?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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.