Free and OnClose caFree

Posted on 2003-03-04
Medium Priority
Last Modified: 2010-04-04

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?
Question by:bnz
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
  • 2

Accepted Solution

Stefaan earned 200 total points
ID: 8063061

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,

LVL 21

Expert Comment

ID: 8063088
if OnClose handler sets action to caFree simply call Form.Close

Expert Comment

ID: 8063101
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 ;-)



Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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