473,728 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15439
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 objectdisposede xception.

Any other suggestions??


"Arne Janning" <sp************ *****@msn.com> wrote in message
news:Ob******** ******@TK2MSFTN GP11.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 objectdisposede xception.

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
23055
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 another function, I want to test if an object is assigned to that
23
25626
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 completed. In order for this to work, I must pass it the form name, and the field names (input tag names). Sometimes I copy/paste the syntax from one page to another and I might forget to change the form name, or an input tag name passed in the
3
13703
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? Remove obvious from e-mail address. Gareth Tonnessen LuvTruth@att.netNOJUNK
9
220303
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
2579
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 skip it. I thought I could check for the existence of an object by comparing to null. However, in the global.asax code below, the "if (Request == null)" line throws the error "Request is not available in this context".
2
2638
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 HomeLink.NavigateUrl="http://www.staffingworkshop.com/" I get the error message: ******************************************************************** Compilation Error Description: An error occurred during the compilation of a resource required
4
7677
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 container class, they will probably try to delete the dynamic object in their code. How do I test to see if the object exists before I delete it? The code below crashes since the dynamic Engine was deleted in the main. However, I need to clean up the...
0
8896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8755
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9125
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3231
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.