Solved

Freeing/Creating forms from other form

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 101
PHP preg_replace code convert to Delphi 14 79
RESTRequest Parameter 4 51
Browsing a TTreeView in Delphi 5 31
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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