E2054
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
E2054 means you called a method or accessed a property that does not exist in the class or record you are using. This is usually caused by a typo in the method name, using the wrong class, or forgetting to declare the method in the class interface. Fix it by checking the spelling, verifying the class type, or adding the missing method to the class declaration.
Affected Models
- Delphi 10.4 Sydney
- Delphi 11 Alexandria
- Delphi 12 Athens
- Embarcadero RAD Studio
- Free Pascal / Lazarus
Common Causes
- Typo in the method name — e.g., writing Compoent instead of Component
- Calling a method that belongs to a subclass but the variable is typed as the base class
- Forgetting to declare the method in the class's interface section (only implemented, not declared)
- Using a method from a newer version of a library that is not in the installed version
- Calling a method on the wrong object — e.g., calling a TStringList method on a TList variable
How to Fix It
-
Check the exact spelling of the method name in the error message against the class declaration.
Delphi method names are case-insensitive but the name must otherwise be exact. Use Code Completion (Ctrl+Space) to see available methods.
-
Verify that the variable's declared type actually has the method you are calling.
If the variable is declared as TAnimal but the method is on TDog, you either need to cast it (MyAnimal as TDog).Bark or change the variable type.
-
If the method should exist but does not, add it to the class declaration in the interface section.
Adding only the implementation without the declaration in the class body will cause E2054 when the method is called from outside.
-
Check the unit's uses clause — the class may be defined in a unit that is not included.
If the class and its methods are declared in UnitA, UnitA must appear in the uses clause of the calling unit.
-
If you are using a third-party library, verify you have the correct version installed that includes the method you are calling.
Library methods added in newer versions will not be available if an older version is installed.
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 can I quickly see all available methods on a class in the IDE?
Type the variable name followed by a dot and press Ctrl+Space to invoke Code Completion. The IDE shows all available methods, properties, and events for that type. This is the fastest way to avoid E2054 — you can see what is available before you type the method name.
Can I call a method that only exists in a subclass?
Yes, but you need to cast the variable to the subclass type first using 'as': (MyBase as TDerived).SpecificMethod Always check the type first using 'is' to avoid an invalid cast exception: if MyBase is TDerived then (MyBase as TDerived).SpecificMethod Alternatively, declare the variable as the more specific type from the start.
What is the difference between E2054 and E2003?
E2003 (Undeclared Identifier) means the name is completely unknown to the compiler — it may be a typo or a missing unit. E2054 (Method Not Found in Class) means the compiler knows the class but cannot find the specific method on it. E2054 is more specific — it tells you the class is valid but the method name is wrong or missing.