All of this crashes at the ShowModal() call with error 1407, "Cannot find window class".
Don't have any idea from this point...
This code should not cause such an error. The problem is in another code.
There are flaws in this code:
1. TForm.Create(nil). Application (not nil) is usually used to avoid thinking about the need to release the form at the end.
2. DebugWindow can be nil, when DebugWindowEnabled = False. ShowDebugWindow not test it.
3. BorderStyle = bsNone. i.e. Caption is not visible - do you really need to assign Caption?
4. Logical variables are usually checked as is, without excessive comparison. if DebugWindowEnabled then... Not if DebugWindowEnabled = True then... or if (DebugWindowEnabled = true) = true then...etc.
5. Your new form is created inside Form1, in the form of a dialog, but it does not have any controls to close itself.