Can not compile exe from Delphi IDE

Hi All,
Still having trouble compiling and running my project from the Delphi IDE

Im using Delphi Community 10.4

So here is what I have found

At first start up I can click Ctl+F9 which compiles and runs my project exe no problem at all

Now after running and closing my project when I try to do that again (ie Ctl+F9) I get

[dcc32 Fatal Error] F2039 Could not create output file ‘.\Win32\Debug\CTC_DB_Interface_01.exe’

So if I now run task manager and look under Background Processes my project exe does not show up

BUT
if I close Delphi my project exe is listed under Background Processes and I can click on the project exe and end the task

Now when I re-open Delphi and then now try compile and run my project exe (Ctl+F9) it compiles and runs OK with no issues

BUT

when I now try to compile the project I’m back to the - Can not create output file stuff

When I run the project exe outside of Delphi - same thing, it shows up in the background process list in task manager

Now it seems to me that when I close my exe the application is not being destroyed

However,
the menu exit procedure is pretty simple - ie just a call to close

procedure TCTC_MainScreen.Exit1Click(Sender: TObject);
begin
Close;
end;

the application runs as

try
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TCTC_MainScreen, CTC_MainScreen);
Application.CreateForm(TDataModule2, FBDataModule);
Application.CreateForm(TCTC_DB_Options, CTC_DB_Options);
Application.Run;
finally
Application.Destroy;
end;

so everything should be getting cleaned up and the project being ended

Can anyone please give me some advice on this as its driving me nuts

Thanks in advance

Kind regards
Grant Brown

I’m assuming that you have tried creating a blank project and confirmed that you don’t have the same problem with that?

If you don’t have the same issue with a blank project, I’d work through a process of elimination to find out what it is in your project that is causing this issue.

If you have source control, I’d suggest going back to a previous version and use divide and conquer to work out which commit introduced the source of this problem.

If you don’t have source control, I’d start with disabling the DataModule and the Options form and see if the problem persists. If the problem persists, then try disabling code in the OnCreate method of your Main Form, etc until you find the culprit. If that doesn’t make a difference, it might be something in an intialisation section of of one of the units that you’re using.

Let us know if you need further help with this.

I think you may have modified the main project file. Delphi by default would have generated something like this probably.

Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TCTC_MainScreen, CTC_MainScreen);
Application.CreateForm(TDataModule2, FBDataModule);
Application.CreateForm(TCTC_DB_Options, CTC_DB_Options);
Application.Run;

It would not have the

Application.Destroy;

line in it

If you program is called

then the issue is the file CTC_DB_Interface_01.exe remains locked after you exit. The Compiler needs to delete the file to build a new one.

The program might still be running but this can also happen if Windows gets its locks in a twist especially if the file exists on a network drive or outside the VM running Delphi.

The fix is to delete the exe in windows explorer. If Windows will not let you do this it will give you a better handle into the reason the lock is in place.

This code closes one form.
Closequery and onclose will be called on that form if assigned .
Onclose can be set to leave the form and application inplay.

You need to ensure all forms are closed and their destructors called.

If you set a break at application.run and in your case Application Destroy my guess is it will never get to the destroy line but you may be looping in Destroy.

Reaching a breakpoint at end. [STOP] will say you program is over.

I agree with Geoffrey Application.Destroy is superfluous and dangerous