Solved

Freeing/Creating forms from other form

Posted on 1998-09-21
3
142 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 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

Independent Software Vendors: 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

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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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…

728 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