Solved

Has a form already been loaded?

Posted on 2001-08-22
8
171 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:riccohb
  • 5
  • 3
8 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 6413413
use findcomponent or iterate through the screen.forms-list
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6413427
or was it application.forms?
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6413517
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6413548
assigned will not work in all cases :-(
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6413579
Hi meikl
Really hmm please explain. I haven't found it to be a problem when dealing with forms internal to the application. :>)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6413643
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 ;-)
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6413815
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. :>)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6416420
:-))
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question