22 Votes

Delphi/Lazarus: Close own Program

Question by Axuter | 2014-08-03 at 19:40

I would like to use a command within my Delphi or Lazarus application that is closing the program itself.

I know, this is very easy, if you only have a single Form (a simple "Close;" is sufficient  in this case). If there are more than one Form, it is enough to close the main form (MainForm.Close; if MainForm ist the name of your main form).

However, in my case, this is not that easy, because closing the application should also work, if there is not yet created any Form at the moment, the command is executed. Are there still ways to handle the exit?

5Best Answer5 Votes

As you have correctly said, you can simply close any GUI application with:


If there is not any main form available, if you do not have a GUI application or if there are any other reasons why you would like to immediately shut your program, you can also use:


This automatically closes all forms/windows that are possibly opened.

Note: You have to include "Forms" into your "USES" section, to be able to access "Application".
Last update on 2021-04-07 | Created on 2014-08-04

ReplyPositive Negative

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.