Solved

Is a form already loaded?

Posted on 2001-08-22
3
250 Views
Last Modified: 2010-04-06
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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6413509
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 6

Expert Comment

by:reddarin
ID: 6417140
Something that kretzschmar pointed out in a similar question:

Assigned(object) checks for nil. So, when you free a form that the user closes, you'll need to make sure you set it to nil since .free does not set it to nil. He recommended using FreeAndNil(object).

reddarin
0
 

Accepted Solution

by:
Bilce earned 50 total points
ID: 6439494
Here's a sample program for your problem.

var
  MyHandle : THandle;
  str   : string;
begin
  str :=TMainForm.ClassName;
  MyHandle :=FindWindow(PChar(str),nil);
  if MyHandle <> 0  then
  begin
    ShowMessage('Cannot run this program cause having same application instance');
  end
  else
  begin
    Application.Initialize;
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
  end;
end.

procedure TMainForm.Button1Click(Sender: TObject);
var str : string;
begin
  str := TMainForm.ClassName;
  ShowMessage('This is the handle for this window : ' + IntToStr(FindWindow(PChar(str),nil)));
end;

For the complete source code and it's example you can email me first and i'll send you the file ...
hope this can help ..

regards...
Billy Lapono
0

Featured Post

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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