Solved

Has a form already been loaded?

Posted on 2001-08-22
8
169 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 60
delphi parse string to params 3 123
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
How to Get Images From Server using App Tethering 11 29
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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