E2196
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
E2196 means you added the 'virtual' keyword to a constructor declaration, which Delphi does not allow in standard class constructors. In Delphi, constructors have their own special polymorphism mechanism through class references — they do not use the virtual keyword like regular methods. Fix it by removing 'virtual' from the constructor declaration.
Affected Models
- Delphi 10.4 Sydney
- Delphi 11 Alexandria
- Delphi 12 Athens
- Embarcadero RAD Studio
- Free Pascal / Lazarus
Common Causes
- Adding 'virtual' to a constructor declaration: constructor Create; virtual;
- Porting code from C++ where virtual constructors have a different meaning
- Misunderstanding that constructors in Delphi work differently from regular virtual methods
- Copying the declaration pattern of a virtual method and applying it to a constructor
- Attempting to make a constructor polymorphic using the same mechanism as regular methods
How to Fix It
-
Remove the 'virtual' keyword from the constructor declaration.
Change 'constructor Create; virtual;' to simply 'constructor Create;'
-
If you need to create objects polymorphically (different subclasses from the same code path), use a class reference (metaclass) variable instead.
Declare a class reference type: type TAnimalClass = class of TAnimal; — then call TAnimalClass.Create to create the right subclass dynamically.
-
If you need a constructor that subclasses can override, use a factory method pattern — declare a regular virtual method called something like Initialize or Build.
The constructor calls Self.Initialize which is virtual — subclasses override Initialize, not the constructor itself.
-
For component writers, use the standard Delphi pattern: constructor Create(AOwner: TComponent); override; — the 'override' here overrides the ancestor's constructor, not a 'virtual' tag.
TComponent's Create constructor is declared as virtual in TObject — that is why 'override' works for constructors of TComponent descendants.
-
Verify your entire class hierarchy if this error appeared after refactoring — ensure the constructor chain is consistent without any stray 'virtual' keywords.
Constructors in Delphi do support 'override' when the ancestor constructor is virtual — but you cannot introduce 'virtual' on a constructor yourself.
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
How does Delphi support polymorphic construction without virtual constructors?
Delphi uses class references (metaclasses) for polymorphic construction — you pass the class type itself as a variable. For example: type TShapeClass = class of TShape; var ClassRef: TShapeClass; ClassRef := TCircle; Shape := ClassRef.Create; This creates a TCircle even though the variable is typed as TShapeClass — without needing virtual constructors.
Why does TObject.Create allow constructors to be overridden if virtual constructors are not allowed?
TObject declares Create as virtual, which is a special case built into the language. This allows descendant classes to override Create using the 'override' keyword. You cannot introduce a new virtual constructor yourself, but you can override one that was already declared virtual in an ancestor class.
What is a class reference (metaclass) in Delphi?
A class reference is a variable that holds a class type itself, not an instance of that class. Declared as 'class of TSomeClass', it lets you call class methods and constructors on a type that is not known until runtime. This is how the DFM streaming system creates components by name — it looks up the class reference and calls Create on it.