Solved

question about release

Posted on 2006-07-07
9
191 Views
Last Modified: 2010-04-05
Hello Guys

I would like to understand this:

Form := Tform.Create(Application);
Form.showmodal;
Form.Release

well, after a showmodal I destroyed my form with release, if I test if Form is like nil, why isn't it nill?

Thanks
0
Comment
Question by:hidrau
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 28

Assisted Solution

by:ciuly
ciuly earned 100 total points
Comment Utility
because the release will not assign a nil value to the form. it cannot do that: an object cannot alter it's address.
if you want to make it nil use freeandnil procedure.
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
oh, and docs say it's recommended not to use release, but free ;)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>oh, and docs say it's recommended not to use release, but free ;)
you mean vice versa -> it's recommended to use release

because -> read online help -> keyword release

meikl ;-)
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
ciuly, in my project, I am using to destroy all forms release, do you think I can have any problem with release.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:ciuly
Comment Utility
meikl, you are right :) for the form, indeed release is the one to be called. thought for the rest of teh components, it's free since release does not exist.
confusion from my part. sorry :)

hidrau, answering your question directly (though meikl responded, so I only emphasis what he said): no problems with release. it is release you should use to destroy a form. using any other method will porbably cause problems (as stated in the docs)

sorry again for the confusion I created.
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
no problem
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 150 total points
Comment Utility
There's a couple ways to do this...

on Close event of your form...  
Action := caFree;

or


if you have code like this you don't even have to worry about setting it to nil...the local var will drop out of scope...

var
  a_frmModal: TfrmModal;
begin
  a_frmModal:= TfrmModal.create(self);
  try
    a_frmModal.ShowModal;
  finally
    a_frmModal.Release;
  end;
end;

OR

  frmModal.Release;  
  frmModal := nil;
//you can do this because frmModal will be freed because of Release...Release does eventually free the object...
//you can always set a pointer to nil...even ones you havn't freed...you'll just have a memory loss...
//but we won't have a memory loss...because you called release before setting the pointer to nil.
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>Release does eventually free the object...
not eventually, it does free the object ;-)

btw. the action caFree calls internal also the release method

meikl ;-)
0
 
LVL 6

Expert Comment

by:House_of_Dexter
Comment Utility
Now lets not muddy the water...

It is eventually...it uses PostMessage which just puts the message on the queue... which unlike Free which runs the code immediately...Release allows the Form the chance to notify anybody who cares...and let them finish up cleaning up...

procedure TCustomForm.Release;
begin
  PostMessage(Handle, CM_RELEASE, 0, 0);
end;


procedure TCustomForm.CMRelease;
begin
  Free;
end;

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

15 Experts available now in Live!

Get 1:1 Help Now