Link to home
Start Free TrialLog in
Avatar of riccohb
riccohb

asked on

Has a form already been loaded?

Is there a way of telling whether or not a form has already been loaded?

I'm writing an app with various forms that the user can open, but I only want the user to be able to open each form once. If it's already open, I just want to bring it to the front instead of loading another copy of it.

Cheers
ASKER CERTIFIED 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
or was it application.forms?
if Assigned(TheForm) then
 TheForm.Show
else begin
 TheForm := TForm.Create(nil);
 TheForm.Show;
end;

make sure you free the form before you the app terminates.


The Crazy One
assigned will not work in all cases :-(
Hi meikl
Really hmm please explain. I haven't found it to be a problem when dealing with forms internal to the application. :>)
crazy,

just try

...
form1 := tform1.create(self);
form1.free;
if assigned(form1) then  //you will go into the then way
...

better way
...
form1 := tform1.create(self);
FreeAndNil(form1);
if assigned(form1) then  //you will not go into the then way
...

its just that assigned isn't other than objectvar <> nil and free do not nil the objectvar

riccohb,

glad to helped you,
thanks for the points :-)

meikl ;-)
Ah hah and there you go. I forgot that I always set the form variable to nil when freeing it so that is why I don't have a problem. I just got in the habit of doing it that way that I forgot about it and assumed that the nil was automatic. Duh. hehehe

Thanks meikl for the reminder. :>)