E2057
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
E2057 means you assigned or passed a constant value that falls outside the declared range of a subrange type. For example, if a type is declared as 1..10, passing the constant 15 causes E2057. Fix it by using a value within the allowed range, or by widening the subrange type definition.
Affected Models
- Delphi 10.4 Sydney
- Delphi 11 Alexandria
- Delphi 12 Athens
- Embarcadero RAD Studio
- Free Pascal / Lazarus
Common Causes
- Assigning a literal constant that exceeds the upper bound of a subrange type
- Assigning a negative literal to a subrange type that starts at 0 or higher
- Passing an out-of-range constant to a function parameter declared as a subrange type
- Initializing an array with a constant index outside the declared index range
- Using a typed constant with a value outside the bounds of its subrange type
How to Fix It
-
Find the subrange type declaration and note its bounds — for example, type TMonth = 1..12 allows values 1 through 12 only.
The bounds are the two numbers separated by .. in the type declaration.
-
Change the constant value to one that falls within the declared range.
If you meant to use 13 for January of the next year, you need a different data model — months 1..12 cannot represent this.
-
If the range is too restrictive for your needs, widen it in the type declaration — change type TDayOfYear = 1..365 to 1..366 for leap years.
Only widen the range if the new values are genuinely valid inputs for all code that uses this type.
-
If the value is intentionally variable and can sometimes exceed the range, use a plain Integer instead of a subrange type.
Subrange types are for compile-time enforcement of a constraint. If the value can legitimately be outside the range, a subrange type is not the right choice.
-
Check array declarations — if an array is declared as array[1..10] of Integer and you try to initialize element[11], that causes this error.
Either resize the array or use an index within bounds.
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 subrange type in Delphi?
A subrange type defines a limited range of an ordinal type — for example, type TMonth = 1..12 creates a type that only accepts values 1 through 12. Subrange types make your intent explicit and let the compiler catch out-of-range values at compile time. They are similar to a constrained integer and are useful for months, days, percentages, or any value with known limits.
Does Delphi check subrange bounds at runtime too?
Yes — with {$RANGECHECKS ON} (or the -R compiler switch), Delphi checks subrange bounds at runtime as well. If a runtime value goes outside the declared range, a EIntOverflow or ERangeError exception is raised. Range checking is on by default in Debug builds and off in Release builds for performance.
Can E2057 happen with enumeration types?
Yes — enumeration types are also ordinal types in Delphi and their valid values are defined by the enumeration members. Trying to assign an integer constant that is outside the ordinal range of the enumeration can cause E2057. Use the enumeration member names (e.g., Monday, Tuesday) rather than integer literals when working with enumerations.