Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNLOAD FORM

Status
Not open for further replies.

gmie

Programmer
Sep 6, 2001
29
0
0
MY
Hello guys..

How to unload form. Example, when commanbutton1 is click then form2 will show but in same time form1 is unload(not just hide) from memory.

TQ
 
hello gmie

Every Delphi program has One main form. all other forms must be children of the main form.
If you look in the project options tabs you will se a forms tab here you can select the main form of your application, (Delphi will assume that the first form you setup when you start a new project is the main form) you must select one form to be that main form and it cannot close independently of any others.
Put it another way
You cannot shut down (remove from memory if you like) the main form and leave child forms running.
There is a lot of stuff related to this in the help files.
Steve..


 
Thanks a lot sggaunt. That is a BIG tips for me. I need guide from all brilliant Delphi programmers here.

TQ
 
Hi gmie,

why in the world do u want to remove that form from memory?

If you really have that many Forms to create and later to destroy (which is not very likely for delphi-beginners ;)
you can write two functions like

procedure CreateForm(FormClass: TFormClass; var Reference);
begin
if TForm(Reference) = nil then
Application.CreateForm(FormClass, Reference);
end;

and

procedure FreeForm(aForm:TForm)
begin
if assigned(aForm)
begin
aForm.Close;
aForm.Free;
aForm:=nil;
end;
end;

That should do it

Shlum

 
Thanks for your code, shlum.
The reason I want to remove the form from memory because to save a memory resource/space. For example, if I open 100 forms then all forms are hide after used(coz we only show 1-3 forms at a time), what happen to your memory. If I not mistaken, it will full with forms. It mean that my program/application will coz the computer working slower. That's why I think I should remove the form from memory after user used it. It mean that I call form when user need it and then remove(from memory) it after used.
That is my idea. I don't know it is right or not. maybe some one can give any idea or somthing to share with me.

Bye...........
 
Don't think there is really a need of destroying the unused forms. If you have that many diefferent forms they are most likely derived from each other... so they share a lot of common resources.
My programs (with lots of forms) use about 2 .. 10 Mbytes of virtual memory, 64-256MB are in the machines...

don't care too much about memory,nowadays it is not the most interesting thing...
 
Ok, I think it solve a lot. Hope U can help me next time coz I'm at begining of 'road' in Delphi. Plz do not just laugh at me....ok :).

TQ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top