?
Solved

Freeing/Creating forms from other form

Posted on 1998-09-21
3
Medium Priority
?
143 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
[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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 800 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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