Debugging Access Violation errors?

It means your code is accessing some part of the memory it isn’t allowed to. That usually means you have a pointer or object reference pointing to the wrong memory. Maybe because it is not initialized or is already released.

Use a debugger, like Delphi. It will tell you on what line of code the AV occurred. From there figure out your problem by looking at the callstack and local variables etc. Sometimes it also helps if you compile with Debug DCUs.

If you don’t have a debugger because it only happens on a client side, you might want to use MadExcept or JclDebug to log the exception with callstack and have it send to you. It gives you less details but might point you in the right direction.

There are some tools that might be able to find these kind of problems earlier by checking more aggressively. The FastMM memory manager has such options.

EDIT

“Access Violation at address 00405772
in module ‘Project1.exe’. Read of
address 00000388.”

So your problem results in a AV at addresss 00405772 in module ‘Project1.exe’. The Delphi debugger will bring you to the right line of code (or use Find Error).

It is trying to read memory at address 00000388. That is pretty close to 00000000 (nil), so that would probably mean accessing some pointer/reference to an array or dynamic array that is nil. If it was an array of bytes, it would be item 388. Or it could be a field of a rather large object or record with lots of fields. The object or record pointer/reference would be nil.

Leave a Comment