Solved

question about release

Posted on 2006-07-07
9
198 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

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.

Question has a verified solution.

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

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 16 hours left to enroll

623 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