question about release

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
LVL 1
hidrauAsked:
Who is Participating?
 
House_of_DexterConnect With a Mentor Commented:
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
 
2266180Connect With a Mentor Commented:
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
 
2266180Commented:
oh, and docs say it's recommended not to use release, but free ;)
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
kretzschmarCommented:
>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
 
hidrauAuthor Commented:
ciuly, in my project, I am using to destroy all forms release, do you think I can have any problem with release.
0
 
2266180Commented:
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
 
hidrauAuthor Commented:
no problem
0
 
kretzschmarCommented:
>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
 
House_of_DexterCommented:
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
All Courses

From novice to tech pro — start learning today.