473,382 Members | 1,332 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.

Form Instances

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

Similar topics

4
by: Tonya | last post by:
Hi, Does anyone have any example of how i can manage forms in my application?? I want to be able to reference my form instances that are currently open from other forms. why cant i open...
16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
6
by: John | last post by:
Hi Is it possible to close a form through code from within itself without using the form name? I just worry that form name can change and the code will stop working. Thanks Regards
12
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for...
17
by: Barret Bonden | last post by:
As an old programmer just now looking at VB.net I have a question: How does one simply open one form from another ? I don't mean how does one create a new instance of that form , but rather how...
7
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up...
4
by: GGerard | last post by:
Hello I have a program where the user can open as many instances of a form as the user wants. The only limit to how many instances can be opened is determined by the limit of the computer...
6
by: Savante | last post by:
I have been writing a datalogging application. It reads in double's into a database. I want to be able to click on a row in a database (holds name of variable and also current value of variable)...
3
by: Jon | last post by:
My main form opens up another form, and from this other form, I'd like to access things in the main form. The problem is that although I know the name of the class of the main form (FormMain) I...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.