Friday, August 05, 2016

Include resource files in your Delphi build process

Quite often people don't know about this neat little feature, as recently in this g+ discussion, too.

You can simply make any .rc file a part of your project and its build process. There's a BrccCompile target defined in your $(BDS)\bin\CodeGear.Delphi.Targets file which is included in every Delphi project by default and it takes care of rebuilding the resources with the brcc32 resource compiler.

One easy way to do this is to select "File\New\Other..." menu item to open the "New Items" dialog and select "Text file" under "Other Files":


In the following "New file" prompt, select ".rc Resource Script" and check the "Add new file to current project" checkbox:


Alternatively, you can create your .rc file in an external editor and drag-and-drop it from the Windows Explorer onto your project's node in the Project Manager treeview.

In either case your new .rc file becomes a part of the project:


At the same time a $R directive similar to this is added to your project's source file (.dpr):

{$R 'New1.res' 'New1.rc'}

That's it. Any modifications to your .rc files will now be recompiled automatically into corresponding .res files and linked into your executable, as a part of the build process. And you can open and edit them easily in the IDE directly, too.

No comments: