Solved

Do I need to free memory from dynamically created form?

Posted on 1998-04-03
2
162 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
[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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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