473,387 Members | 1,757 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,387 software developers and data experts.

Is it a valid Object Instance?...

Hi,

how can i find out whether a object is a valid instance or not?

I have a object called objCF (base class is a Form) and i want to
find out whether this object is a valid insatnce or a null reference.

This must be accomplished in C#...

Thanks in advance...
Nov 17 '05 #1
4 3821
if (objCF != null)
{
// Valid instance
}

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Kerem Gümrükcü" <ka*******@hotmail.com> escribió en el mensaje
news:us**************@tk2msftngp13.phx.gbl...
Hi,

how can i find out whether a object is a valid instance or not?

I have a object called objCF (base class is a Form) and i want to
find out whether this object is a valid insatnce or a null reference.

This must be accomplished in C#...

Thanks in advance...

Nov 17 '05 #2
Hi Carlos,

this was also my first idea, but it does not work. let me describe what i
want to do:

I have a class called "ConfigurationForm" and i have a class (beside a lot
of other classes ;-) ) called
MainForm. Inside the MainForm's class there is a dynamic (private)
ConfigurationForm Object. This
Object will be initialized inside the MainForms Constructor, but the form is
still invisible until it
will be raised visible with "cf.Show();". This is done by Menu from the
MainForm or from a TrayIcons
Menu in the TaskBar. Both share the same code routine. When i open the the
CF(ConfigurationForm)
with cf.Show() and close it later with cf.Close(), the pointer or in our
case the reference will be no more
valid to the cf Object. So far so good! It would be easy always to open a
new instance of the CF and
make it visible with cf.Show(). I cant use cf.Visible because of some
special needs of the application.

Its somethink like this i want to do, but how, because the "null"-Thing does
not work, i always get a false
as return value:

if(cf == null){

cf = new ConfigurationForm();
cf.Show();

}else{

if(cf.Visible == false){
cf.Visible == true; // possibly cf.Show();
}
}

This "cf == null" thing does not work! I always get a false as return value,
even when i use this expression on a valid (instanciated) cf object
Ok, i could handle this with try--catch, but this is not a clean solution
anway.
Any more ideas........anybody?
Thanx in advance...
Kerem Gümrükcü

Nov 17 '05 #3
If you always close the form by code using cf.Close() then you can set cf to
null too and your test will work always. Otherwise, you can try testing the
cf.IsDisposed property:

if (cf == null)
{
cf = new Form2();
cf.Show();
}
else if (cf.IsDisposed)
{
cf = new Form2();
cf.Show();
}

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Kerem Gümrükcü" <ka*******@hotmail.com> escribió en el mensaje
news:OD**************@TK2MSFTNGP14.phx.gbl...
Hi Carlos,

this was also my first idea, but it does not work. let me describe what i
want to do:

I have a class called "ConfigurationForm" and i have a class (beside a lot
of other classes ;-) ) called
MainForm. Inside the MainForm's class there is a dynamic (private)
ConfigurationForm Object. This
Object will be initialized inside the MainForms Constructor, but the form
is still invisible until it
will be raised visible with "cf.Show();". This is done by Menu from the
MainForm or from a TrayIcons
Menu in the TaskBar. Both share the same code routine. When i open the the
CF(ConfigurationForm)
with cf.Show() and close it later with cf.Close(), the pointer or in our
case the reference will be no more
valid to the cf Object. So far so good! It would be easy always to open a
new instance of the CF and
make it visible with cf.Show(). I cant use cf.Visible because of some
special needs of the application.

Its somethink like this i want to do, but how, because the "null"-Thing
does not work, i always get a false
as return value:

if(cf == null){

cf = new ConfigurationForm();
cf.Show();

}else{

if(cf.Visible == false){
cf.Visible == true; // possibly cf.Show();
}
}

This "cf == null" thing does not work! I always get a false as return
value,
even when i use this expression on a valid (instanciated) cf object
Ok, i could handle this with try--catch, but this is not a clean solution
anway.
Any more ideas........anybody?
Thanx in advance...
Kerem Gümrükcü

Nov 17 '05 #4
Yes, it was this disposed thing what i was looking for!
Thank you very much...
Best Regards

Kerem Gümrükcü
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DDF | last post by:
I took this snippet from a book I foudn online. Public Class Demo Public Structure ValueDemo Public X As Integer End Structure Public Class RefDemo Public Y As Integer End Class Public...
6
by: John-Arne Lillebø | last post by:
Hi. I run into this problem and i could need some help to solve it. The project is an ASP.NET Web project. Including code sample of the problem. Any idea what is causing the error message ?...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
4
by: Materialised | last post by:
Hi All, I have a strange issue, and I am not sure if it is a error on my part, or a visual studio bug. I am using VS.Net 2003 Enterprise. I have 2 event handlers as follows: Public...
1
by: planet | last post by:
Hi, I wish I can solve this problem not having recode the sub. Here is goes: I got this error' specified cast is not valid' at the second line. from the code Sub...
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
30
by: Filimon Roukoutakis | last post by:
Suppose that we have a function f(Object*& obj) and have declared a global std::vector<Object*vec; Is it valid to do void g() { vec.push_back(new Object);
13
by: jehugaleahsa | last post by:
Hello: Today I learned that the + operator cannot be passed a delegate. I get an error from the CLR saying I have an invalid program. With that, I was wondering if someone could tell me what...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.