Access Violation
C++ Builder Programming Language
Severity:What Does This Error Mean?
An access violation in a C++ Builder application is a runtime crash — the program tried to read from or write to a memory address it does not have permission to access. The most common causes are a null pointer dereference, using an object after it has been deleted, or writing beyond the end of an array. Running the program in the C++ Builder debugger (F9) automatically stops at the crashing line.
Affected Models
- C++ Builder 10.x (Alexandria)
- C++ Builder 11 (Sydney)
- C++ Builder 12 (Athens)
- RAD Studio 11 and 12
Common Causes
- Calling a method on a pointer that is nullptr or was never initialised
- Using a VCL component pointer after the component has been freed (dangling pointer)
- Writing past the end of an array — buffer overrun
- Accessing a class member through a cast pointer of the wrong type
- A thread accessing a VCL component that was created in a different thread
How to Fix It
-
Run the program from the C++ Builder IDE using F9 (Run with debugging). When the access violation occurs, the debugger will stop at the exact crashing line.
The debugger's Call Stack window (View > Debug Windows > Call Stack) shows the sequence of function calls that led to the crash, which is essential for tracing the root cause.
-
Inspect the pointer or object being accessed at the crashing line. Hover over it in the debugger to see its current value. If it is 0x00000000 (nullptr) or a garbage address, the pointer is invalid.
A null pointer means the object was never created or was already freed. Trace back through the call stack to find where the pointer should have been initialised.
-
Guard against null pointers before dereferencing them. Before using a pointer, check: if (myPointer != nullptr) { ... }
For VCL component pointers assigned in the Form Designer, they are valid for the lifetime of the form. For pointers you create manually with new, ensure they are initialised before use and not accessed after delete.
-
If the access violation involves VCL components and threads, ensure all VCL access is done on the main thread. Use Synchronize() or TThread::Queue() to marshal calls to the main thread.
VCL is not thread-safe. Accessing a TLabel, TEdit, or any VCL control from a background thread without synchronisation causes access violations that are often intermittent and hard to reproduce.
When to Call a Professional
Access violations in shipped applications are bugs that must be fixed by a developer. They cannot be resolved by users. If you are a developer, use the C++ Builder debugger to locate the crashing line.
Frequently Asked Questions
Is an access violation the same as a segmentation fault (segfault)?
Effectively yes — on Windows, access violations and segfaults are the same underlying OS exception (STATUS_ACCESS_VIOLATION). The term segfault is used on Linux and macOS; access violation is the Windows equivalent.
Can an access violation corrupt data without crashing immediately?
Yes — writing to a memory address that belongs to another variable (but not to a protected page) corrupts that variable silently. The crash may occur later at an unrelated location. This is why access violations are among the most difficult bugs to debug — the crash site and the root cause are often far apart.