HPP emit (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index




{$HPPEMIT 'string'}

The HPPEMIT directive adds a specified string to the header file generated for C++. For example: {$HPPEMIT 'typedef double Weight;' }. Whenever there is a unit that must be linked in even if there are no references to it, Delphi code should use the HPPEMIT directive. The HPP header generated from that unit then contains some macros that ensure that, when included in a C++ source file, the header causes the unit to be linked in.

HPPEMIT directives are output into the "user supplied" section at the top of the header file in the order in which they appear in the Delphi file.

The HPPEMIT directive accepts an optional END directive that instructs the compiler to emit the string at the bottom of the .hpp file. Otherwise, the string is emitted at the top of the file.


{$HPPEMIT     'Symbol goes to top of file'}
{$HPPEMIT END 'Symbol goes to bottom of file'}

For C++ on Mobile Platforms, {$HPPEMIT LINKUNIT} Replaces #pragma link

For C++ applications, {$HPPEMIT LINKUNIT} replaces #pragma link on mobile platforms.

The Delphi run time has units that must be linked in order to enable some functionality. In C++, auto-linking was previously achieved using the following directive:

{$HPPEMIT '#pragma link "<unitname>"'}

Now you should use the following directive instead:


Generating Namespace Declarations for C++

Additionally, two new HPPEMIT directives have been added in XE5 Update 2:

    This generates C++ namespace declarations for the current unit.
    For example, if you use {$HPPEMIT OPENNAMESPACE} in the FMX.Bind.Editors.pas unit, the following content will be generated in the corresponding .HPP file:
namespace Fmx
namespace Bind
namespace Editors
    This generates closing braces to the namespaces declared with {$HPPEMIT OPENNAMESPACE}.
    This tells the Delphi compiler not to generate the "using namespace <unit-name>;" that is typically seen at the end of the .HPP generated from a .PAS unit. This directive avoids polluting the global namespace and can be very helpful in avoiding ambiguities. The same effect can be achieved by defining the DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE macro. However, the latter might cause failures in cases where code does not use qualified names (for instance, in event handlers generated by the IDE).

See Also