|
Interface reference counting |
Top Previous Next |
|
What is translated > Types > Records, Classes, Interfaces > Interfaces > Non-generic interfaces > Interface reference counting In Delphi, interface instances are managed through automatic reference counting. If an object that implements an interface is assigned to an interface-typed variable, it will be automatically destroyed when no more references to it exist.
Delphi2Cpp preserves this behavior in portable C++ by providing a custom smart pointer class:
template <typename T> class DelphiInterface<T>;
This class replicates Delphi’s reference model by providing:
Portable C++ (non-C++Builder)
DelphiInterface<IMyInterface> Intf = new TMyClass(); Intf->DoSomething(); // Calls Release() automatically when going out of scope
C++Builder
DelphiInterface<IMyInterface> Intf = new TMyClass(); Intf->DoSomething(); // Safe and consistent with portable mode
|
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |