简体   繁体   中英

Auto rename compiled file in Delphi XE2

I use Delphi XE2 and I have a project called PGetBase. In this project, there is a module with a constant declaration. For example:

const
   FragH = 5;
   FragW = 4;
...

After compiling, the file is called PGetBase.exe. Is it possible to make the name of the build file dependent on the constants declared in the module, eg PGetBase_5_4.exe, by making use of a Post-Build event ?

Add a project to the projectgroup which creates an executable that uses the same unit and changes the filename. Build and run that executable in the Post-Build event.

Microsoft Build knows nothing about the Pascal language and cannot parse the sources.

However you may extract "5" and "4" into some external text files.

const
   FragH = 
   {$I Frag_h.txt}
   ;
   FragW = 
   {$I Frag_W.txt}
   ;

Then make a simple program (or script: WSH, PowerShell, etc), that would be launched from post-build events. You program would read those file and rename the Delphi-made PGetBase.exe to anything you wish.

PS. Of course one can parse the source unit to regain those constants, rather than offloading them into external storage. Comments hold the discussion pro et con.

PPS. NGLN came wit ha neat idea. Rather than parsing the file, you can just include that unit as part of your renamer project. Then you can add a pre-build event, that would compile(make) renamer and in post-buid the renamer would have those constants within itself. While calling make/dcc32 would probably be slower than just parsing the sources from inside the version-neutral pre-compiled renamer.exe, that NGLN's approach is elegant and self-contained in its own way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM