delphi

Is it ok to create an object before Application.Initialize?


Is it ok to create an object (my own class) before Application.Initialize?


Solution

  • Is it ok to create an object (my own class) before Application.Initialize?

    Certainly. You can do anything you like in your program (*.dpr file).

    In fact, you may have been doing this already, without knowing it. If you have ever used the initialization section of a unit -- or a modern class constructor -- you have executed your own code prior to Application.Initialize.

    Writing custom code at this early time of your program's lifetime is neither unusual nor bad practice.

    But you should be extra careful, of course, because the pre-Application.Run environment is subtly different from the Application.Run environment. For instance, an unhandled exception will kill your app.