Delphi Interfaces

From RAD Studio
Jump to: navigation, search

Go Up to Support for Delphi Data Types and Language Concepts

The Delphi compiler handles many of the details in working with interfaces automatically. It automatically augments the reference count on an interface when application code acquires an interface pointer and decrements that reference count when the interface goes out of scope.

In C++Builder, the DelphiInterface template class provides some of that convenience for C++ interface classes. For properties and methods in the RAD Studio libraries that use interface types in Delphi, the C++ wrappers use a DelphiInterface that is built using the underlying interface class.

The DelphiInterface constructor, copy constructor, assignment operator, and destructor all increment or decrement reference counts as needed. However, DelphiInterface is not quite as convenient as the compiler support for interfaces in Delphi. Other operators that provide access to the underlying interface pointer do not handle reference counting because the class cannot always tell where that is appropriate. You may need to explicitly call AddRef or Release to ensure proper reference counting.


See Also