Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Do I need to free memory from dynamically created form?

Posted on 1998-04-03
2
Medium Priority
?
163 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 60 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

704 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