Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

Free and OnClose caFree

Hi

If I in a OnClose event for a form have set Action to caFree and then call Free for the form. Should this result in a memory access error or is this another fault in my program?
0
bnz
Asked:
bnz
  • 2
1 Solution
 
StefaanCommented:
Hi,

Actually I wouldn't think that will cause an Access violation, since the caFree in fact doesn't free the form immediately.  What it does is send a CM_RELEASE message to the form, so that all other pending messages will be handled prior to the destruction of the form.

In fact, you shouldn't really .Free forms, instead you should use .Release so that all pending messages are handled before the form is destroyed.  If you check the Delphi help for .Release, you will see that they even state the you should use .Release over .Free for forms.

Best regards,


Stefaan
0
 
ziolkoCommented:
if OnClose handler sets action to caFree simply call Form.Close
ziolko.
0
 
StefaanCommented:
That would depend on the the way he is showing it, if he is showing it Modally ( using .ShowModal ), the Close would be rather obsolete.

As I said before, simply use .Release instead of free.  The release will send a CM_RELEASE message, the form will process all messages until it reaches the CM_RELEASE and when it reaches that one it will destroy itself.  Simple as that ;-)

Regards,


Stefaan
0

Featured Post

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now