Solved

question about release

Posted on 2006-07-07
9
197 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 177
HTML text in the body of an email (delphi code) 12 258
How to debug For loops? 3 74
Automatic field translation delphi 10.2 6 45
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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