|
Interface declarations |
Top Previous Next |
|
What is translated > Types > Records, Classes, Interfaces > Interfaces > Interface declarations Delphi interfaces define a contract via the interface keyword, and often include a GUID to support COM identity and interface querying (e.g., Supports). The translated C# code uses the standard interface construct, optionally extended by a base interface (IInterface) to simulate Delphi-style type casting and compatibility features.
Delphi Example
type IMyInterface = interface ['{12345678-1234-1234-1234-1234567890AB}'] procedure DoSomething; end;
In Delphi, the interface declares a method DoSomething. The GUID enables runtime interface querying and is part of Delphi's COM compatibility. Interfaces implicitly descend from IUnknown unless specified otherwise.
C# Translation
public interface IFoo : IInterface { void DoSomething(); };
IInterface is a placeholder base interface defined by Delphi2C# to simulate Delphi-style interface hierarchies.
It does not include methods like AddRef or QueryInterface.
The GUID can be declared using [Guid("...")], but is not required in standard .NET usage.
Base Interface: IInterface
public interface IInterface { // Dummy - no methods necessary for .NET, but necessary for type casting }
- In .NET, interfaces do not require a base unless semantic compatibility with Delphi is needed. - IInterface serves as a type anchor for functions like Supports<T>(), which mimic Delphi's interface querying behavior. - In COM-compatible builds, IInterface may be replaced or extended with a true IUnknown contract.
Notes
- Multiple interface inheritance is supported in both Delphi and C#. - Interface members in Delphi map directly to method declarations in C#.
|
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |