Solved

question about release

Posted on 2006-07-07
9
195 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:2266180
2266180 earned 100 total points
ID: 17061482
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:2266180
ID: 17061483
oh, and docs say it's recommended not to use release, but free ;)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17062054
>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
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.

 
LVL 1

Author Comment

by:hidrau
ID: 17062097
ciuly, in my project, I am using to destroy all forms release, do you think I can have any problem with release.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17062218
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
ID: 17062257
no problem
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 150 total points
ID: 17077611
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
ID: 17081622
>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
ID: 17082154
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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