If I call Application.Terminate OR Application.MaiForm.Close inside a method. the application doesn’t terminate!
procedure doSomething;
var
ErrorFound: boolean;
begin
[...]
try
if ErrorFound then
Application.Terminate;
finally
[...]
end;
end;
I cannot understand why.
Please note that I’m calling Application.Terminate from inside a Try…Finally block, in the Try section.
Most likely you are calling
Application.Terminatefrom a busy loop that itself does not terminate. If you enter an event handler but never return from it then callingApplication.TerminateorApplication.MainForm.Closewould indeed be futile. These routines that close an application are cooperative. They post messages to the main message loop requesting that the application gracefully shuts down.For example, the following code would exhibit the symptoms you describe:
Another (more likely) possibility is that you are calling this function from inside a modal form but not closing the modal form.
Unless you show more code, we are reduced to making guesses like this.