Search code examples
delphidelphi-7

Delphi 7 open a cmd when start


Every time i run my Delphi application, a 'cmd' window open, and some of my users are complaining about this window, saying it crashes their computer, i want to learn WHY this cmd window open, and how make it not open.

My .dpr file is like this

... 
Frm05715 in 'fontes\Frm05715.pas' {Form05715}, 
Frm99903 in 'fontes\Frm99903.pas' {Form99903}; 
{$R *.res} 
begin 
Application.Initialize; 
... 
Application.Run; 

And the cmd window open even before the Application.Initialize, which is the first line that runs


Solution

  • As I explained in a comment, a way to debug this is to put a breakpoint on Application.Run in your .Dpr file.

    If the cmd window opens before the breakpoint trips, the cmd window is likely being opened in the initialization code of one of your units, which will be straightforward to debug. You can do that by following the steps in my answer to this q.

    If you check the value of the Count variable in InitUnits in System.Pas, you might be surprised how high it is, often over 200. However, you can use a binary search to rapidly identify the guilty unit by putting a breakpoint on the line

    TProc(P)();
    

    and setting its pass count initially to count / 2. Once you've identified the unit in question, you could use the debugger's Trace into (F7) command to identify the code which launches the Cmd window, if that isn't obvious from inspection of the unit's intialization code.