Object Pascal Class Declarations (__declspec)

From Appmethod Topics
Jump to: navigation, search

Go Up to Classes Index

Syntax

__declspec(<decl-modifier>)

Description

The decl-modifier argument can be delphiclass or pascalimplementation. These arguments should be used only with classes derived from Object Pascal classes, as follows:

  • You must use __declspec(delphiclass) for any forward declaration of classes that are directly or indirectly derived from TObject.
  • Use the __declspec(pascalimplementation) modifier to indicate that a class has been implemented in the Object Pascal language. This modifier appears in a Object Pascal portability header file with a .hpp extension.

Note: Another argument, delphireturn, is used internally to mark C++ classes for Object Pascal-compatible handling in function calls as parameters and return values.

The delphiclass argument is used to create classes that have the following compatibility:

  • Object Pascal-compatible RTTI
  • Object Pascal-compatible constructor/destructor behavior
  • Object Pascal-compatible exception handling

A Object Pascal-compatible class has the following restrictions:

  • No virtual base classes or multiple inheritance is allowed.
  • Must be dynamically allocated by using the global new operator.
  • Copy and assignment constructors must be explicitly defined. The compiler does not automatically provide these constructors for Object Pascal-derived classes.
  • Must publicly inherit from another Object Pascal class.

See Also