473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 15416
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
23
by: Randell D. | last post by:
Folks, I have written some scripting tools that are compatable with alot of my pages - For example, I've created a script that will check to ensure certain form fields that require data, are...
3
by: Gareth Tonnessen | last post by:
I need to have a clean way to determine whether a query exists without trying to open it and getting an error message. Is there a simple way to determine whether an object exists in a database?...
9
by: Chris Ashley | last post by:
How do I check if an object exists in Javascript? EG: if (document.getElementById("product").value == null) { prodValue = ""; } else {
4
by: Mark Berry | last post by:
Hi, I'm working on my "last resort" error block for a web application. If the error occurs after a Request has been made, I want to show the URL. If the Request object is not available, I'll...
2
by: tshad | last post by:
I have an object that may or may not exist on a page. Therefore, I test for it. But it doesn't seem to work if I do the following: if not HomeLink is nothing then...
4
by: rickbird | last post by:
I have a composition object that is written in C++. The container class deletes the dynamic object in its destructor. However, if someone creates the object in the main and passes it to the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.