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

Form Instances

P: n/a
Hi,
I'm using VS.NET 2003. I've a small problem using the OOP concepts. I want
to know before creating an instance of a class, to check whether any
instances earlier created exists.

Now for example. I'm calling a method to create a Instance of Form, and
Before creating an object instance of the form, I want to make sure that
there isn't any object instances created earlier which still exists and want
to know how to destroy that previous Instance.

example:
(assume that TForm is a base class)

Dim objForm1 as New TForm
If not any previous object instances of TForm exists then
objForm1.ShowDialog
else
Destroy the previous Instance

How can I write this logic as VB.NET code?????

--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hifini,

Dim objForm1 as New TForm

If you do this, than objForm1 is absolute a new object.

There can be another object with the same name, however it is not necessary
that it is the same, by instance

Sub one
dim objForm1 as New TForm1
end sub

Sub two
dim objForm1 as New TForm2
end sub

This are two complete different objects.

Another question is if you want to reshow an already opened form object. For
that is the not in the standard intelisence showed IsDisposed

if Not myform.IsDisposed then
myform.show
else
dim myform as new WhatEverFormType
myform.show
End if

I hope this helps,

Cor
I hope that this gives an idea

Cor
Nov 21 '05 #2

P: n/a
Hi Cor,
Thanx for your valuable information. However I got another question. Now
after using the form object I would like to distroy it to save memory. In
what Form event can I call:

objForm1.dispose or what ever method which destroys the form object instance?

Thanx,

--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.
"Cor Ligthert [MVP]" wrote:
Hifini,

Dim objForm1 as New TForm

If you do this, than objForm1 is absolute a new object.

There can be another object with the same name, however it is not necessary
that it is the same, by instance

Sub one
dim objForm1 as New TForm1
end sub

Sub two
dim objForm1 as New TForm2
end sub

This are two complete different objects.

Another question is if you want to reshow an already opened form object. For
that is the not in the standard intelisence showed IsDisposed

if Not myform.IsDisposed then
myform.show
else
dim myform as new WhatEverFormType
myform.show
End if

I hope this helps,

Cor
I hope that this gives an idea

Cor

Nov 21 '05 #3

P: n/a
Hifni,

It depends forever where you have instanced your form object.

Did you do that private or global, than at least the address lives forever
as long as the class where it is in is lives. A form has a bunch of controls
referencing to it.

Therefore don't worry if not really necessary about the memory used by a
form. The GC will release it, when it is sure that it will not be reused
because there is no reference anymore to it. What can mean that there will
be a lot of releasinges before that.

This is exactly why it is called managed code.

I hope this helps,

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.