E2066
Delphi Programming Language
Severity: MinorWhat Does This Error Mean?
Error E2066 means Delphi found the end of a statement without the semicolon it expected, or found two expressions next to each other with no operator between them. In Delphi, every statement in a begin/end block must end with a semicolon (except the very last one before end). A missing semicolon or a misplaced expression causes the parser to lose track of where one statement ends and the next begins.
Affected Models
- Delphi 2005 and later
- RAD Studio
- Lazarus/Free Pascal (similar error)
Common Causes
- Forgetting a semicolon at the end of a statement inside a begin/end block
- Two identifiers or expressions placed next to each other with no operator between them
- A missing assignment operator (:=) that makes two adjacent names look like a missing operator
- An extra or misplaced keyword that confuses the parser
- An incomplete expression left in the code by accident
How to Fix It
-
Jump to the error line. Look at the end of the line above it. Is there a semicolon? If not, add one.
In Delphi, every statement in a begin/end block ends with a semicolon — except the last statement before 'end'.
-
Look at the flagged line for two adjacent identifiers with nothing between them. One is probably missing an operator or the line above is missing a semicolon.
Example: 'A B' with nothing between — either A needs a := operator to assign to B, or the line before A is missing a semicolon.
-
Check all if/then/else structures. The statement after 'then' does not need a semicolon if it is followed by 'else'. Adding one there is a common mistake.
Correct: if X then DoA else DoB; — Incorrect: if X then DoA; else DoB; (semicolon before else breaks the structure).
-
Look for any assignment statements that are missing the := operator. In Delphi, assignment uses := not = (which is used for comparison).
Example: 'Count 5' is missing ':=' — it should be 'Count := 5;'
-
Use the IDE's code formatter (Ctrl+D or via the Edit menu) to reformat the code. This sometimes makes structural problems much easier to spot visually.
A well-formatted block of code makes missing semicolons and misaligned begin/end pairs obvious at a glance.
When to Call a Professional
E2066 is always something you can fix yourself. The error points to the line where the parser got confused. Look at that line and the one before it for a missing semicolon or operator.
Frequently Asked Questions
Why does Delphi require semicolons between statements?
Semicolons are statement separators in Pascal (and Delphi). They tell the compiler where one statement ends and the next begins. Without them, the parser cannot determine the boundaries between statements when reading the code top to bottom.
Should the last statement in a begin/end block have a semicolon?
Technically no — the semicolon separates statements, so the last one does not need one before 'end'. But adding it is harmless and many developers do it consistently. Delphi accepts it either way.
Why does putting a semicolon before 'else' cause a problem?
In Delphi, if/then/else is a single statement. Adding a semicolon after the 'then' part tells the compiler that the if statement is finished. When it then reads 'else', it has no matching 'if' and raises a syntax error. Always omit the semicolon on the line just before 'else'.