[fpc-pascal] Re: Fpc Access Violation if AppConfigDir doesn't exist.

Sven Barth pascaldragon at googlemail.com
Tue Feb 12 13:49:20 CET 2013

On 12.02.2013 13:29, Giuliano Colla wrote:
> On 02/11/2013 09:14 PM, Sven Barth wrote:
>> It would be nice if you could minimize the problemematic code further
>> step by step so that we can see what caused the "missing dialog".
>> Maybe it's a bug somewhere else...
> I've made some further experiments with my minimal test.
> Test form is just a Form with a Close button (BitBtn Kind=bkClose).
> The full code is the following:
> One may test two conditions: with try..finally and with try..except.
> Even with this minimal sheds some light on the matter.

It indeed does, but not as you think.

> Try..finally situation, with IDE and Debugger.
> Press the Close button. A debugger error notification is shown. Pressing
> "Continue", an error dialog is displayed: "Unable to create ... press OK
> to Ignore...etc.":
> Pressing OK (no harm should come, just the file can't be written) the
> form isn't closed as it should, and it's still there.
> Pressing again the close Button, FormClose is executed again, and the
> same dialog is shown. No way to close the form, unless you press Cancel
> on the error dialog.
> Why FormClose doesn't close the form in presence of an error (handled by
> a try..finally) when writing the ini file?
> Launching from command line, you have the same behavior, and an
> additional information when you select Cancel:
> WARNING: TLCLComponent.Destroy with LCLRefCount>0. Hint: Maybe the
> component is processing an event?
> Try..except situation, from IDE and Debugger.
> Press the Close button. Debugger Notification. Pressing Continue my
> message dialog is shown. Pressing OK on my dialog the form is closed and
> the program is terminated.
> Launching from command line, no console messages.
> My conclusion is that one can't properly handle INI files with just a
> try..finally construct, as all examples show, because a possible error
> will propagate outside the construct, with unpredictable effects (in
> this case the FormClose procedure doesn't properly complete).

The problem is not INI files, but more how OnClose is handled. OnClose 
is called whenever the user tries to close the form and if an assigned 
event handler raises an exception it seems that the calling code assumes 
that the form should not be closed. In my example I used OnDestroy which 
seems to be handled more gracefully.

I'd suggest you to ask on the Lazarus list whether it is intentionally 
that you can't close a form of which the OnClose event handler raises an 


More information about the fpc-pascal mailing list