Delphi / Object Pascal · Exception

Runtime Error 213: Collection index out of range

What does Runtime Error 213: Collection index out of range mean in Delphi / Object Pascal?

An index into a TCollection or similar indexed collection class was outside the collection's current bounds.

Runtime Error 213: Collection index out of rangeDelphi (VCL) · Delphi (FireMonkey)

Condition

An index into a TCollection or similar indexed collection class was outside the collection's current bounds.

Fix

Check the index against the collection's Count property immediately before use, rather than relying on a count captured earlier that may be stale if items were added or removed since.

Pending source verification. Not yet checked against official documentation.

Related exception