Just to leave a point on a extra problem if code must be on main form OnCreate.
Try such code on the Main Form OnCreate event. It does not work as expected, main form is shown, then the application is finished.
To be able to see it, add another form and put on its creation a long loop.
It seems like all the Application.CreateForm
on the main project source are executed.
Sample code:
procedure TMyMainForm.FormCreate(Sender: TObject);
begin
ShowMessage('[1] This must allways be shown');
if mrOK=MessageDlg('Exit?',mtConfirmation,[mbOK,mbCancel],0)
then begin
Application.Terminate;
Exit;
end;
ShowMessage('[2] This must not allways be shown');
end;
procedure TMyOtherForm.FormCreate(Sender: TObject);
begin
ShowMessage('[3] This must not allways be shown');
end;
With that code messages [1] and [3] are allways shown.
Only way to not show [3] is to call Halt.
Note: Why such code on MainForm OnCreate? Simple answer could be, the exe checks conditions to be run and see they are not meet (missing files, etc), rude one (sorry for that), just because i want/need to.
Application.MainForm.Close;
– SuaveApplication.Terminate
, so you can call that directly when needed. However, do not that it can only be called in the context of the main thread, not a worker thread. – HuesmanApplication.MainForm.Close
won't simply callApplication.Terminate
but it will process bothOnCloseQuery
andOnClose
events of the main form if they were assigned. You can even prevent the application from closing by settingCanClose
variable ofOnCloseQuery
event to false. But callingApplication.Terminate
won't process those events. – HebnerExit;
afterApplication.Terminate;
instead ofHalt;
– KarisaExit
does nothing but leave the current function or procedure. BTW, it should not be confused with theexit
function of the C standard library. – Benfield