Which is the proper way to terminate a delphi application?

前端 未结 3 1254
既然无缘
既然无缘 2021-02-05 06:41

I would like to terminate a Delphi application without executing any other code line and I\'m wondering about which is the proper way to do this. Furthermore, I would like to kn

3条回答
  •  盖世英雄少女心
    2021-02-05 07:20

    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.

提交回复
热议问题