Board index » cppbuilder » Using New Unit vs New cpp file and Header File

Using New Unit vs New cpp file and Header File

I have a Console app in BCB 5 Pro that is running and all is fine. I want to
add some new classes to it and wonder should I do this via the New Add Unit
option or New Add CPP file and New Header file. Is there a difference in the
final result between the two methods. The online help just states that the
New Unit is IDE managed and "For your own code that is not IDE managed or
IDE assisated use NEW Cpp firl and NEW Header file"

Thanks in advance

Jeff

 

Re:Using New Unit vs New cpp file and Header File


Quote
"Jeff Douglass" <.> wrote in message

news:3d80b50e$1@newsgroups.borland.com...

Quote
> Is there a difference in the final result between the two methods.

When you create source files in Builder via the "New Unit" command Builder
creates hidden code to help manage the unit correctly.  If you'll look at
the CPP file of a newly created unit you will see the following line:

  #pragma package(smart_init)

This creates two exported functions for initializing and finalizing the unit
in respect to other units in your project (and any included packages).  Look
at the help for smart_init to get more of an idea of what this does.

When you create source files individually the two functions are not created
but you are bypassing the Builder safety net for unit initialization.  If
you do not initialize global variables in your unit then it is safe to
create units in this manner.

However, you can achieve the same effect by creating a unit and then
commenting out the above pragma line.  In this way you can allow Builder to
create the standard boiler plate CPP and H files (which you would probably
end up having to type manually anyway).

HTH,

- Clayton

Other Threads