Solved

Has a form already been loaded?

Posted on 2001-08-22
8
167 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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6413548
assigned will not work in all cases :-(
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now