Jul 9, 2010

C++ Builder 6 Redux

I recently had to resurrect BCB6 from the dustbin of my hard drive and start using it to maintain a brownfield project for a new client. In the span of years since I’ve used this tool I’ve forgotten many, many things about using it. As I relearn them I’m putting them in this blog entry both for myself (in case this ever happens again) and for any other developer that finds themselves in this situation. There are more modern versions of this tool but the original .DLL was developed in BCB6 and I already owned it so it’s what I’m using.

Top 14 (and counting) things to remember about BCB 6

  1. Borland (now named Embarcadero ) has a developer forum for the product that I have found helpful.
  2. Files don’t save automatically by default, even when building.  Under the Tools menu, correct this by using the Environment Options... and check the indicated checkbox.  The IDE does automatically create a backup of every file you edit so if you rely on this feature (you should really be using a source code control system instead) you may not want to auto save.  The backup feature can be turned off. It’s under the Tools->Editor Options, under the Display tab. The Eclipse IDE has done the best job I’ve seen with local backups. They keep a user configure number of backups and manage them with a mini SCCS. That way if you don’t check in to to your repository frequently you still can do code compares and rollbacks to this local repository. With the BCB6 feature you can only get back to your last saved file and as far as I can tell there are no automated tools to let you switch back to it or to do comparisons. image
  3. There are several add on tools that can make life easier while using the IDE. Torsten Reindorf  (on the aforementioned forum) supplied this list of essential tools for tricking out the IDE
  4. Essential keyboard/mouse shortcuts
    • F12 – Toggle between Form and Code
    • Ctrl-j –Bring up the popup for pasting in template code (type a shortcut first like switch(ctrl-j)
    • Ctrl-space – force auto complete – this is one of the worst features in BCB6 –it is slow and often doesn’t work, any compile error (like writing a method without putting in the .h file first) tends to completely break it. If you’re used to Visual Studio you just have to suck it up. It’s good for improving your appreciation of everything Zen.
    • Ctrl-F6 – or Right-click in text editor and the first option toggles between the source and include file. It appears you can’t have both open at once.
    • Ctrl-F7 (Make)  does a compile of only the required files. Build (F7) appears to do a full clean build.
    • Ctrl-F – the find dialog – The find in all files is particularly useful
    • Alt-Up arrow  - Find declaration for item under cursor. Alt-down doesn’t take me back to the implementation and I haven’t been able to find a keyboard shortcut that does.
    • Form shortcuts – When you have layered items in the form using the down arrow will take you to items behind the first item. Using the Esc key will move you up through the hierarchy of items. Ctrl-arrow keys moves items and Shift-Arrow keys resize them.
    • Ctrl-Shift I and U to indent and un-indent blocks of code (no tool for auto reformatting whole module that I could find)
  5. I could not find a keyboard shortcut for compiling the current unit so I added a button to the toolbar for doing it.
  6. Getting a quick message box  use what appears to be a global method ShowMessage(“put message here”). Good when used for fast debugging. More elaborate dialogs can be done with the MessageBox  or MessageDlg class.
  7. The Project-Options (Alt-F7) (or right click on the project in the Project Manager) will be your friend. When you go to debug make sure to visit the compiler Tab and hit the Full Debug button.  On the Directories/Conditionals tab there is a Final Output entry (the .DLL I used inherited this and I got errors when building because the directory didn’t exist). The CodeGuard panel looked interesting and I vaguely remember it could find problems,  but when I tried it everything broke. A better thing to enable and explore on a new project. 
  8. Testing the .DLL requires a host application. That is set using the Run->Parameters menu. (Thanks to Remy Lebeau of TeamB for reminding me about this dialog.)image
  9. The IDE doesn’t really integrate well with Lint as far as I can tell. You can add Lint to the tool menu and have it launch in a DOS window. The image shows the settings I used.  image

    //  Standard lint options for Borland C++ Builder 6
    +fpa        // pause before closing the message window
    lnt\co-cb.lnt  //Tell lint it is the Borland compiler
    //You'll usually have your own file here too so that you don't have to litter
    //you're source with //lint comments
    options.lnt  -d_FLAT_ -u_SMALL_ -si4 -sp4
    -i"C:\Program Files\Borland\CBuilder6\Include"
    -i"C:\Program Files\Borland\CBuilder6\Include\Vcl"
    +e900       // always produce at least one line of output
    -t4         // Presume that tabs are every 4 stops
    //This is an example of how you specify your own folders that contain headers
    -wlib(0) //turn off lint for libraries+
  10. The Borland compiler is very forgiving about a common cut and paste error. If you define a method first and then cut and past the method signature into the header, the compiler won’t complain if you leave the ClassName:: prefix on. However, other compilers do so it’s a good idea to get in the habit of deleting that.
  11. There doesn’t seem to be any built-in support for using source code control inside the IDE. I use Tortoise-SVN with project locker so I’m just trying to get used to going to Explorer and checking code in from there. I find it easy to forget and I check in much less frequently than I should. It’s also more of a pain when doing code compares. (I know I’m spoiled)
  12. If you accidentally create an event handler from the form, just ignore it. Return to the form and continue editing. Do not delete the empty handler by hand. If you do you have to also delete the declaration. If you leave it alone (and empty) the next time you compile the IDE will remove the method for you. This is the one feature I wish VS had.
  13. Debugging – I’ve had some strange problems with Debugging. Sometimes the application just ignores the breakpoints. When you look at the source code the little dots that indicate a line on which a break point can be set are all missing. When that happens I delete all the .obj files and all the files the build process creates. In the case of the current dll that includes the following extensions dll, tds, ilc, ild, ilf, and ils. I then quit the IDE (may not be necessary) and restart it, then do a Build of the application and it seems to cure itself. [Update] You also have to make sure you have debugging enabled. To do this use the Project-Options menu (Alt-F7). In the dialog that appears click on the Compiler tab. Then click on the Full Debug button. Then click OK  to dismiss the dialog and do a full rebuild of your project.
  14. Quick and Dirty Output – In visual studio cout<<”some data” just shows up in the IDE’s console window. I haven’t found the equivalent yet in BCB6 but you can do OutputDebugString(“some data”) and it will show up in the Event Log which you can view via the View->Debug Windows->Event Log (Ctrl-Alt-V)

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.