Solved

Do I need to free memory from dynamically created form?

Posted on 1998-04-03
2
155 Views
Last Modified: 2010-04-06
Hi,

I have a Delphi 2 app using MDI.  The application only allows ONE copy of each window to be in existance.  Code fragment is....

///////////////////////////////////////////////////
procedure TMainForm.CommissionPlanMenuClick(Sender: TObject);
var
  Child: TCommPlanF;
  N    : Integer;  
begin
 
 
  { create a new MDI child window }
  Child := nil;
  with Application.MainForm do
    for N := 0 to MDIChildCount - 1 do
      if MDIChildren[N] is TCommPlanF then
        Child := MDIChildren[N] as TCommPlanF;
  if Child = nil then
    Child := TCommPlanF.Create(Application)
  else {_ NOT if Child = nil then _}
    with Child do
    begin
      if WindowState = wsMinimized then WindowState := wsNormal;
      BringToFront;
    end; {_ with Child do _}
end; {_ procedure TMainForm.CommissionPlanMenuClick(Sender: TObject); _}

///////////////////////////////////////////////////////

This dynamically creates the window.  The question becomes...  Do I need to do something to free the memory after the window is closed or is this done for me automatically?  If I need to free the memory, do I use the TFORM.RELEASE method?

Thanks
GTAS
0
Comment
Question by:gtas
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 20 total points
ID: 1361271
Yes, you need to free it yourself - as any object you create at run-time.

In this case though, you can handle the Close event (OnClose handler) of the created form and put this simple line in it:

Action := caFree;

to automagically free the form when the windows is closed.

-julio

BTW, why don't you Break your loop when you've found your form? (just to tell some more :)
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1361272
Ah... anycase, to free a form - as any other Object - the correct way to go is:

MyForm.Free;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now