Form Instance

  • Thread starter Thread starter Guest
  • Start date Start date
Niggy said:
Is it possible to check if an instance of a form exists? TIA.

Do you mean a specific instance or just any instance at all? If you have
a variable of the type of your form and you don't know if you have
instantiated it yet, you can check for null:

MyForm myForm;
...
if (myForm == null)
// do something

Be aware that myForm will only be automatically initialized to null if
it's a class member (field), not if it's a variable in a method.

If you mean you want to find out whether just any instance of a form
exists, I don't think that's possible. You should store away the
references to forms you create, so you can later find out what you
created or not.


Oliver Sturm
 
Lloyd said:
Application.OpenForms
what about that hey?
2.0 required...

Interesting, I hadn't seen that yet. I just tested it, though, and I
found out that you have to be careful: The OpenForms collection holds
only forms that are actually visible on screen (as the name suggests).
So it could be that there are any number of form instances that are not
in that collection because the forms aren't currently visible.



Oliver Sturm
 
If you continously dim a variable to hold a new form, will you eventually
run out of memory or does the dim replace the current instance of that form?
 
Niggy said:
If you continously dim a variable to hold a new form, will you eventually
run out of memory or does the dim replace the current instance of that form?

If you "forget" the old instance of the form you just created, it should
be free to get collected by garbage collection (if there aren't any
other references to the same form held in other places). So at least
when there's not enough memory left (or a while earlier than that),
garbage collection will kick in and free a lot of those old instances
that aren't referenced any more.



Oliver Sturm
 
Back
Top