Delphi / Object Pascal · Exception

EAccessViolation Exception

What does EAccessViolation Exception mean in Delphi / Object Pascal?

Raised when code dereferences a nil or otherwise invalid pointer, writes into memory reserved for executable code, or touches an address that has no virtual memory mapped to the process. It commonly follows use of a freed object, an uninitialized interface or object reference, or corrupted array/string indexing that walks off the end of allocated memory. The default VCL handler catches it and shows a generic 'Access violation at address...' message box instead of crashing outright.

EAccessViolation ExceptionDelphi (VCL) · Delphi (FireMonkey)

Condition

Raised when code dereferences a nil or otherwise invalid pointer, writes into memory reserved for executable code, or touches an address that has no virtual memory mapped to the process. It commonly follows use of a freed object, an uninitialized interface or object reference, or corrupted array/string indexing that walks off the end of allocated memory. The default VCL handler catches it and shows a generic 'Access violation at address...' message box instead of crashing outright.

Fix

Reproduce under the IDE debugger or attach a stack-trace library (madExcept, EurekaLog) to get a real call stack instead of guessing from the raw address. Add nil checks before dereferencing objects/interfaces, verify object lifetime since a freed object accessed later is the single most common cause, and run with FastMM4 full debug mode to catch heap corruption early.

Related exception