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.Terminate
from a busy loop that itself does not terminate. If you enter an event handler but never return from it then calling Application.Terminate
or Application.MainForm.Close
would 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:
procedure TMyForm.Button1Click(Sender: TObject);
begin
while True do
Application.Terminate;
end;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With