3

I've had a major annoyance with the C++ Builder IDE for some time now. When I code I always use a standard layout for the code files. I have a standard header that I use, including, ie. the License of the file, filename, date, etc.

But I haven't been able to find anywhere to insert this, so that when I - for instance - create a new unit, get this header inserted automatically. Of course I can just paste it in, every time, but it gets a bit irritating to use time doing this.

So my question is - is it possible to create a file template for default C++ files or modify the existing ones so that they always start with my predefined layout. My fear is that just as with most other things in the C++ Builder IDE, this is hardcoded into it.

Currently creating a new unit creates a .cpp file with:

//---------------------------------------------------------------------------


#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

and a corresponding header file with:

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#endif

This is what I wish to alter to my own defined layout.

I'm using Codegear C++ Builder 2007.

Johan
  • 74,508
  • 24
  • 191
  • 319
Tommy Andersen
  • 7,165
  • 1
  • 31
  • 50

2 Answers2

4

See "Adding Items to the Object Repository" in the help file.

Basically, 1. Create the unit file(s) as you wish 2. Go to Project -> Add to Repository 3. Add information. 4. It will be available from the File -> New... area

There are also ways to share and edit repository items. The default distribution items are not quite as flexible, but creating your own should do just what you need.

Kris Kumler
  • 6,307
  • 3
  • 24
  • 27
  • I think I tried doing that but had problems adding units to the repository, seemed I could only add controls. Further more this will only work with units. I will have to make a version for a form, unit, datamodel, control, etc. In order of always having the default header information present. I will ofcourse give it a shot tomorrow, and see how it goes. But in my oppinion not having such an option is a mistake from Codegear. Thanks for the answer though, I will look into it shortly. – Tommy Andersen May 24 '09 at 22:41
  • It worked that way, don't know why I didn't think of that before - thank you. Still it can irritate me that there isn't a default way to add headers. But then again, that is whole different story. – Tommy Andersen May 26 '09 at 08:46
1

For the defaults, see the answers to the question on reducing the "uses" clause boilerplate also located on stack overflow. This would require the same changes.

Community
  • 1
  • 1
skamradt
  • 15,366
  • 2
  • 36
  • 53
  • The downside to that though, wouldn't it likely be overwritten when the product is upgraded? – Kris Kumler May 22 '09 at 23:24
  • Actually that is a pretty nice to know. But I would have wished they had moved the data to an external file. Preferably in the user directory. Thanks for sharing. – Tommy Andersen May 26 '09 at 14:08