Non-generic interfaces

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Interfaces > Non-generic interfaces

Non-generic interfaces in Delphi provide a mechanism to separate implementation details from their usage.

Historically, they are based on the Component Object Model (COM) and are COM-compatible by default—that is, they inherit from IUnknown and implement reference counting via AddRef and Release.

 

In Delphi, these methods are typically declared as _AddRef and _Release to distinguish them from regular members, although the underlying COM behavior remains consistent.

Each interface is associated with a GUID, which enables runtime type resolution through QueryInterface, Supports, and the as<T> operator.

 

Unlike classes, Delphi interfaces support multiple inheritance, making them particularly well-suited for component-based architectures with high levels of abstraction.

 

 

Scope of translation

 

In Delphi2Cpp, non-generic interfaces are translated into COM-style C++ interfaces with deterministic GUIDs.

They are managed using DelphiInterface<T> smart pointers, which automatically handle reference counting and ensure RAII-style memory safety.

 

The translation focuses exclusively on v-table-based interfaces (i.e., standard Delphi/COM interfaces).

It does not support:

 

dispinterface constructs
full COM automation via IDispatch

 

Instead, the objective is to provide a Delphi-compatible C++ representation, with:

 

GUID-based interface tables
reference counting via AddRef/Release
dynamic type checking (as<T>, Supports)
Delphi-style interface mapping macros
This ensures full compatibility with how Delphi uses interfaces in its RTL and component framework, while avoiding the complexity of full COM automation.

 

 

Interface table generation

 

Delphi2Cpp offers two strategies for generating interface tables:

 

Explicit generation — Delphi2Cpp emits interface tables directly into the translated C++ source.
Automatic generation — Interface tables are created at compile time via the InterfaceTableGenerator mechanism, which relies on modern C++ templates.

 

Note

The choice between explicit and automatic interface table generation is controlled by a checkbox in the Delphi2Cpp options.

 

 

Required adjustments in C++

 

Because C++ lacks a built-in interface system comparable to Delphi, specific adjustments are required. Delphi2Cpp provides:

 

custom base classes such as TCppInterfacedObject
smart pointers like DelphiInterface<T> for RAII-based reference counting
dynamic interface resolution via generated GetInterface implementations
Together, these components reproduce the structural design and semantic behavior of Delphi interfaces in portable C++.

 

 

Topics covered in this section

 

This section explains how Delphi2Cpp reproduces the full semantics of non-generic interfaces:

 

GUID's

Interface declarations

Interface implementation

Interface reference counting

Interface type checking

Portable interface emulation

 

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content