Solved

Freeing/Creating forms from other form

Posted on 1998-09-21
3
136 Views
Last Modified: 2010-04-06
I have an application in which there are 5 forms: a main menu which always exists and four forms that get created and destroyed from the main menu form.  

On the main menu there are 5 buttons: Quit which destroys the four other forms, and one button for each of the four forms to display the associated form. When the user clicks on one of the button to show one of the four forms, it must check if the form is already created. If it is it shows it otherwise it first has to create it. When the Quit button on the main menu is clicked, the four other forms are destroyed (gracefully).

What is the best way of doing this ?

Thank you.

0
Comment
Question by:skylinka
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1340512
You can use this and as soon as the forms are closed the self destroy them....

var
  newform : TForm;
begin
  newform := TForm.Create(self);
  with newform do
  try
    ShowModal;
  finally
    free;
  end;
end;

YOu can also use the button to destroy the forms.... here is an explanation

if you call SomForm.Free; the free method first checks if the forms has been destroyed, if it hasn't then it destroys it if it has then nothing happens...so ifyou have a button that frees all forms and call it Forms.Free; it will check if the forms are freed and if they are not freed then they will be destroyed(freed)...

Vik;->
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340513
You can also you TList;
Implementetion
var
  List : TList;

in Form's OnCreate() event
begin
  List := TList.Create;
end;

in Form's OnDestroy() event
begin
  List.free;  
end;

Where you create the forms....

var
  F : TForm;
begin
  F := TForm.Create(self);
  List.Add(F);
  F.Show;
end;

In the Quit Button's OnClick() event
var
 i : integer;
begin
  for i := 0 to List.Count - 1 do
    TForm(List.Items[i]).Free;
end;

Vik ;->
0
 

Author Comment

by:skylinka
ID: 1340514
Thank you. Good idea.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

21 Experts available now in Live!

Get 1:1 Help Now