Solved

Do I need to free memory from dynamically created form?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

16 Experts available now in Live!

Get 1:1 Help Now