Visual Basic 6.0
' Quit the application Private Sub Cancel_UIButton_Click() Unload Me ' If there are no problems, ' this stops this application ' and triggers code in the ' Unload, QueryUnload, and Terminate events End ' Otherwise, this forces the application to quit End SubNotice that, by itself, the End command stops program execution and that code placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed.
Unload SomeName_UIFormcould be used to terminate a named form.
The Cancel button's Cancel property should be set to True so that the Esc key will activate it.
Close; // Use this in the form's *.pas file Form1.Close; // Be sure to use the correct form name MainForm.Close;When you click the 'x' in the title bar, choose Close from the form's System menu, Windows generates a Close message which eventually calls the Close method of the active form. (The same method called by the Close commands above.)
If you use Application.Terminate, then onCloseQuery and onClose will not be called.
The Halt procedure performs an abnormal termination and no additional code is executed.
In a dialog box, the Cancel button's Cancel property should be set to True so that the Esc key will activate it. Then add the following to the OnClick event.
procedure TForm2.Cancel_UIButtonClick(Sender: TObject); begin Close; end;
When a form is being created and its Visible property is True, the following events occur in the order listed: