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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
May be try something like this
if Form1=nil then ....
if Form1=nil then ....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you're creating the form as follows:
Application.CreateForm(TFo rm, 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(TFo rm, 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.
Application.CreateForm(TFo
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(TFo
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Trust me . You don't need all this lengthy code. Use something simple such as my suggestion.
Regards,
Hypoviax
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 ;-)
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
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?