E2120
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
E2120 is a variant of 'interface type expected' that occurs specifically around GUID declarations or interface ancestry issues. This happens when a GUID is declared in a non-interface context, or when an interface attempts to inherit from a non-interface type. Fix it by ensuring all interface declarations use the correct syntax and that the base type is also an interface.
Affected Models
- Delphi 10.4 Sydney
- Delphi 11 Alexandria
- Delphi 12 Athens
- Embarcadero RAD Studio
- Free Pascal / Lazarus
Common Causes
- Declaring an interface that inherits from a class instead of another interface
- Placing a GUID declaration in a class body instead of an interface body
- An interface declaration that is missing the interface keyword and uses class instead
- Inheriting from IInterface incorrectly or from a type that is not derived from IInterface
- A syntax error in the GUID string causing the parser to misinterpret the interface declaration
How to Fix It
-
Check the interface declaration — it must use the 'interface' keyword, not 'class': type IMyInterface = interface(IInterface)
The base type in parentheses must also be an interface, not a class.
-
Verify the GUID is placed correctly — it goes on the line immediately after the opening 'interface' line in square brackets and quotes.
Example: type IMyInterface = interface ['{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}'] procedure DoSomething; end;
-
Generate a fresh GUID using Ctrl+Shift+G in the Delphi IDE and paste it into the interface declaration.
Each interface should have a unique GUID. Do not copy the GUID from another interface.
-
If the interface does not need a GUID (not used with QueryInterface), you can omit the GUID entirely — just declare the methods.
Interfaces without a GUID cannot be used with the 'as' operator for runtime interface querying.
-
Ensure the interface inherits only from other interfaces, and ultimately from IInterface or IUnknown at the root.
All Delphi interfaces that need COM compatibility must have IUnknown at their root. For non-COM interfaces, IInterface is the standard root.
When to Call a Professional
This is a compiler error — no professional repair needed. Fix it by reading the error message and correcting the code. The Delphi IDE highlights the exact line causing the problem.
Frequently Asked Questions
What is a GUID and why do Delphi interfaces use them?
A GUID (Globally Unique Identifier) is a 128-bit number that uniquely identifies an interface across all machines and all time. Delphi uses GUIDs to support COM (Component Object Model) — the Windows component technology that lets programs share objects. When you query an object for an interface using 'as', Delphi uses the GUID to find the right interface implementation.
Do all Delphi interfaces need a GUID?
No — a GUID is only required if you use the interface with QueryInterface (the 'as' operator) or with COM. For purely internal interfaces used only through direct variable assignments, you can omit the GUID. As a best practice, always add a GUID using Ctrl+Shift+G — it costs nothing and future-proofs the interface.
What is the difference between IInterface and IUnknown in Delphi?
IInterface is the standard Delphi root interface — use it for all new Delphi interfaces. IUnknown is the COM root interface — it is identical in Delphi to IInterface but the name IUnknown comes from Microsoft COM conventions. For new Delphi code, always use IInterface as the base unless you specifically need COM interoperability.