Link to home
Start Free TrialLog in
Avatar of Smokulas
Smokulas

asked on

How do I tell if a form has already been created?

I am creating a form and freeing it when I no longer need it. My problem is I am not sure how to tell if my form has been created already. It's a simple list box really, and if the user clicks the right button I end up with more than one instance of the form. Help?
ASKER CERTIFIED SOLUTION
Avatar of arjanh
arjanh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arjanh
arjanh

Alternatively, you could show the popup form modally (do a subform.ShowModal instead of subform.Show). Then the user must close the listbox subform before he can press any key on the main form. That wouls also solve your problem.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
May be try something like this
if Form1=nil then ....
SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you're creating the form as follows:

Application.CreateForm(TForm, Form);
or
Form:=TForm.Create(Self);


then when you free it you would do:

Form.Free;
Form:=nil;

so to check if the form is created or not you would do:

if not Assigned(Form) then ...


It's a good idea to fo the creation as folows:

if not Assigned(Form) then Application.CreateForm(TForm, Form);

and then free it when you don't need it anymore, this way you will never have an error or a second instance of the same form.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Trust me . You don't need all this lengthy code. Use something simple such as my suggestion.

Regards,

Hypoviax
Hypoviax,

your suggestion has three fallbacks
- more than one form with same caption in same application instance
- more application instances
- another application may have the same caption

just for clarify

meikl ;-)

Very true krezschmar i did not think of this, thank you for your comment.

Smokulas do not accept my answer if the conditions expressed by krezschmar are true.

Regards,

Hypoviax
Back up a half a step ... why do you need to know "if" it has been created?