Delphi / Object Pascal · Exception

Runtime Error 216: EAccessViolation

What does Runtime Error 216: EAccessViolation mean in Delphi / Object Pascal?

The program tried to read or write memory it does not have valid access to, commonly by dereferencing a nil pointer or an object reference that was already freed. This is the single most reported Delphi runtime error, and the one developers mean when they just say access violation.

Runtime Error 216: EAccessViolationDelphi (VCL) · Delphi (FireMonkey)

Condition

The program tried to read or write memory it does not have valid access to, commonly by dereferencing a nil pointer or an object reference that was already freed. This is the single most reported Delphi runtime error, and the one developers mean when they just say access violation.

Fix

Turn on Tools, Debugger Options, Language Exceptions, Stop on Delphi Exceptions so the debugger breaks exactly where the violation happens rather than reporting only a raw memory address after the fact. A common but non-obvious cause is calling Application.ProcessMessages from inside an event handler, which lets the same event fire again before the first call finishes and corrupts state the second call is still using.

Pending source verification. Not yet checked against official documentation.

Related exception