C++ Builder IDE >> Associating .cpp and .h files in a unit

by salamander1965 » Sun, 19 Jun 2005 08:44:13 GMT

I've been using BCB6 fairly regularly for about a year now, but recently
a problem came up that I have yet to find a solution for (although I'm
still trying).

To state the obvious, the IDE normally associates a .cpp and a .h file
as separate sub-tabs under a single unit tab. This has been the case
for me for most of a year and I'm sorta fond of the feature, but
starting a couple of days ago, the IDE now loads the .cpp and .h files
of a unit as separate, stand-alone files.

If I create a new unit in my project, close BCB6, and reopen the
project, the newly created unit appears properly with two sub-tabs. I
tried cutting and pasting from one of my (no longer correctly handled)
units into the new unit (which just got done reloading correctly),
saving the files, closing the IDE and reopening it -- the .cpp and .h in
the unit are no longer associated.

Has anyone had, or heard of, this problem? I haven't been able to find
in any of the project's files something that looks like it associates a
particular source and header file as a unit. Any suggestions would be
appreciated.



C++ Builder IDE >> Associating .cpp and .h files in a unit

by David Dean » Mon, 20 Jun 2005 02:31:47 GMT


In article <42b4bfa6$ XXXX@XXXXX.COM >,



It only does it if the .h file has the correct header guards. There
are some bugs which cause it to open them in separate windows sometimes,
but with the correctly named header guards, it works most of the time.

--
-David



C++ Builder IDE >> Associating .cpp and .h files in a unit

by salamander1965 » Mon, 20 Jun 2005 03:27:39 GMT






Thanks for the information. In fact, I'm checking the newsgroup
messages and got your reply because I was going to post that I had come
to the same conclusion.

What caused my problem was that I had changed my header guards to use a
GUID-like unique portion. I made the changes last thing one night but
didn't re-open the project for a couple of days, so I initially missed
the cause-effect connection. If I change the header guards back to the
original form, everything works as it should. In retrospect, it makes
sense because the header guards for a unit are managed by the IDE, and I
had forgotten that.

Based on a little bit of playing around with it, it looks like the
header guard in the .h file must be the same as the .cpp file name with
an additional 'h' tacked onto the end. Any change to the guard name
removes the unit connection between the .cpp and .h files (although
changes in case does not appear to be noticed). In addition, the IDE
apparently looks for more than just the name -- the complete guard must
be present: #ifndef name, #define name, and #endif. Changing the
#ifndef to an #ifdef, or leaving out the #define name part, removes the
unit connection.

I like the idea of being able to have 'guaranteed' unique header guards
such as you get by generating a GUID for the guard name, and it's still
possible to do that in units -- you just have to be sure to have a
'proper' guard first in the file that contains nothing other than the
#define name statement.

Again, thanks for the info, David.



Associating .cpp and .h files in a unit

by johnp » Fri, 26 Aug 2005 13:53:16 GMT

How do I get BCB6 to open .cpp AND .h files in the same editior window.
I can only open these in separate edit windows and when editing/recompiling
BCB6 will sometimes swop out the header for the .cpp file. I have to alt-F6
between cpp and .h files. I previously used BCB3 which never had this
irritating behavour.

johnp




Associating .cpp and .h files in a unit

by Remy Lebeau (TeamB) » Fri, 26 Aug 2005 15:03:18 GMT






What you are asking for sounds like a split window, which AKAIK you cannot
do.


Correct.


You have to do that anyway.


Gambit





Associating .cpp and .h files in a unit

by Ed Mulroy » Sat, 27 Aug 2005 00:24:59 GMT

I am not positive as to what you want. One guess as to what it is suggests
that you try this:

Alter the start of the header file from something like this:
-----------------
#ifdef HEADNAMEH
#define HEADNAMEH
-----------------

To be like this:
-----------------
#ifdef HEADNAME_H
#define HEADNAME_H
-----------------

. Ed







Associating .cpp and .h files in a unit

by salamander1965 » Sat, 27 Aug 2005 01:42:28 GMT





Thanks for the reply. Actually, I got it straightened out a while
back (see my reply post earlier in the thread). It turns out I had
messed up the association between .cpp and .h by putting in my own
header guards. What I use now in the header file is:

#ifndef UnitNameH //just to keep .cpp/.h association in place
#define UnitNameH
#endif
#ifndef __H_FC614824_0B4B_476d_A2FC_897331D3971C
#define __H_FC614824_0B4B_476d_A2FC_897331D3971C
// Header contents inserted here
#endif

It's a little messy, but it lets me keep the .cpp/.h association
intact, and it lets me use a unique GUID-like header guard, which I like.

-- salamander



Similar Threads

1. Splitting units into several .cpp files

Hello NG,

I wrote a form that counts about 6000 lines of code and this's pretty long 
in compiling ...
There's a "clean" way to split it into several sub-units?

-- 
Michele Santucci
===================
Celin Avio S.r.l.
Software Dev. Manager
--------------------------------------
tel. +390187564080
Via Fontevivo 21/M
19126 La Spezia
=================== 


2. when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

3. when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

Hai Rolf Magnus

the real problem is when i try ti access it give Bus Error (Core Dump)
i don't no why? when i try to access the varible argv[1] or
argv[argc-1] anything it gives the Bus Error
Thanks

4. Problem opening serialized file via Open command associated with file type

5. Switching tabs between cpp/h and between units with the keyboard

Hello

I generally like to use the keyboard as much as possible when working.  I've
always been frustrated that I could not switch between units or between the
cpp/h file of a unit without the mouse.  However, I never thought to ask if
there are shortcut methods for these functions.  DOH!  So now I'm asking.

Ciao
    Bill


6. Translate C++ code to Delphi (pascal unit)... C++ File (CCL.cpp) & Delphi Unit (ftCCL3.pas)

7. Header files / CPP files ?

This has got to be something really simple, but I'm pretty baffled...[VC++ 
.NET 2003]

In the header file I define the class interfaces, in the CPP file the class 
functions, and the
CPP file  #includes the header file. Looks like Stroustrup style code.

The only way I can get it to complile is to declare (again) the class within 
the cpp file.

If I don't redeclare it but instead just put all the 
Classname::Method(parameters){ code };
in the CPP file,  I get thousands of compile errors.  They seem to object 
whenever I use any of
the managed types. The functions that don't use anything but ints, etc. seem 
to compile OK.

What is simple that I'm missing?

  -- Tom






8. Debug Assertion Filed! File: winocc.cpp - Microsoft Visual C++/VC++