The Close method calls the OnClose event. If it returns caFree then the Close method calls Release. Release posts a CM_RELEASE message to the form. If you are calling Release in the OnClose event handler, then Release gets called twice, which means the second message tries to get processed via a non-existant form.
 
Free calls Destroy if Self <> nil. Destroy, well, destroys the object instance. If you call either of these methods during an OnClose event, you will get a GP Fault since you have just killed the object that made the call. When the OnClose event returns, any remaining code that references the form will cause the GP Fault, since the form no longer exists.
 
Note that if you do this:
  with TAModalForm.Create(Self) do
  try
    ShowModal;
  finally
    Free; (or Release, or Destroy)
  end;
 
and you return caFree in the forms OnClose handler, a GP Fault will occur, since the form has been destroyed before you call Free (or Release, or Destroy).
 
In other words, if OnClose returns caFree, then do not attempt to free the form: Delphi has done this for you. If you return caHide or caNone from the OnClose, then you (or the form owner object) is responsible for destroying the object.
 
heck, I've been programming in Delphi since '93 (yep, V1.0) and just last weekend I tried to kill an MDI Child form twice. Took me hours to figure out what the bug was. :-/
 
 
Whats the difference between Release and Action := caFree are different?
I thought they would have ended up doing the same thing.
 
 

Reply via email to