Compiling GExperts while the DLL is loaded in the IDE

If you have tried to work on GExperts (or any other DLL-based Delphi IDE expert) you have probably encountered this annoyance: Of course you want GExperts to be active in your IDE so you can use its features. But if you then compile it, the output file already exists and is locked because it is opened by the IDE.

So, you either live without the features while working on it, or don’t compile it while the IDE is open. I for one find that really annoying.

But, there is a partial solution for this:

Windows allows you to rename/move DLLs that are locked, so it’s possible to replace the file. And to make it convenient, you can use a pre-build event. So, I changed the pre-build event to this:

call ..\..\buildtools\prebuild.cmd $(PROJECTPATH)

(The first is a call to my standard prebuild script which handles version information.)

This works, kind of. Since once the DLL has been moved, the destination file exists and cannot be overwritten, move will fail and return a result of 1, which causes the pre-build event to fail.

I could have unchecked the “Cancel build on error” option, but that is not a clean solution to the problem. So instead, I opted for calling a batch file that always returns 0:

@echo off
echo moving %1 so the DLL can be compiled even though it is currently loaded in the IDE
move %1 %1~
exit /b 0

and calling it instead:

call ..\..\buildtools\prebuild.cmd $(PROJECTPATH)
call ..\..\buildtools\movedll.cmd $(OUTPUTPATH)

Works nicely for me.

I have added that script to my build tools, so I can use it everywhere I need it.

And, of course, debugging the expert also works fine now, because when you start a second instance of the IDE it will load the freshly compiled DLL.