Is it a valid Object Instance?...

  • Thread starter Thread starter Kerem Gümrükcü
  • Start date Start date
K

Kerem Gümrükcü

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...
 
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
 
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ü
 
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
 
Yes, it was this disposed thing what i was looking for!
Thank you very much...


Best Regards

Kerem Gümrükcü
 
Back
Top