?
Solved

Freeing components

Posted on 1998-03-20
3
Medium Priority
?
163 Views
Last Modified: 2010-04-06
Do I have to close free all objects created with Free
before terminating application, or all of them are
automatically free-ed?
0
Comment
Question by:bor061297
3 Comments
 
LVL 2

Accepted Solution

by:
mvz121697 earned 200 total points
ID: 1360664
As a general rule:
Free all components which you are creating yourself,
with the Create-method.
So if you are dropping components on your form, don't worry about freeing, Delphi does it for you.

But if you are creating components dynamicly, you have to free them, like this:

var fm:TForm;
begin
fm:=TForm.create(Self);
try
  // stuff...
   fm.ShowModal;
finally  
  fm.Free;
end;


BTW, if you don't follow this rule for VCL-components,
they will still automaticly be freed, when the parent is destroyed. (The parent is the object you supply as a parameter in the create-method).  
You can also let the Application be the parent, like this:

fm:=TForm.Create(Application)

If you don't free this yourself, it will be freed when the application ends.


Greetings,
MvZ




0
 
LVL 4

Expert Comment

by:d003303
ID: 1360665
just a little cosmetics, the owner is passed in the Create method. Also, if the owner is freed, all owned components are freed, too. This does not depend on the parent property.
Generally, all components on a form are owned by the form. If e.g. a label resists on a panel wich resists on a form, the owner property of all two components is the form. The parent of the label though is the panel, the parent of the panel is the form. And normally all forms are owned by the application and have no parents (except MDIChild wich has the MDIForm as a parent).

Slash/d003303
0
 

Author Comment

by:bor061297
ID: 1360666
If I create a BitMap with:

Bitmap := TBitMap.Create;

is it automatically freed when application ends?
And, who owns Bitmap created in this way
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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