Invalid pointer operation - Delphi XE

I can't seem to figure this out. My program compiles and starts successfully, but during debugging only it gives a window with the message "Invalid Pointer Operation" when the program is turned off. I carefully checked all the FormCloseQuery and FormDestory events for any syntax or logical error. I did not find them, and they execute as expected, without any error.

enter image description here

When I tell the compiler that it breaks when the Invalid Pointer Operation fails, it does nothing but freeze the program. At this point, I had to complete or kill the process.

How do you rate this?

Thanks in advance,

+8
debugging exception delphi delphi-xe
source share
4 answers

An Invalid Pointer exception is thrown by the memory manager when attempting to free invalid memory. This can happen in three ways.

The most common is that you are trying to free an object that you have already freed. If you enable FastMM FullDebugMode, it will detect this and immediately indicate a problem. (But be sure to create a map file so that it has the information needed to create useful stack traces.)

The second way is that you are trying to free memory that was allocated somewhere other than the memory manager. I saw this several times while passing a string from Delphi EXE to Delphi DLL that did not use the shared memory manager function.

And the third way involves messing with pointers directly and probably doesn't apply to you. If you try FreeMem or Dispose bad pointer that does not reference the actual block of memory allocated by FastMM, you will get this error.

Most likely the first. Use FullDebugMode and you can easily find the source of the problem.

+25
source share

Invalid pointer operations occur when you tell the Delphi memory manager to free memory that does not belong to it. Three ways are possible:

  • Releasing a pointer or object that has already been freed.
  • Using FreeMem to free up what was allocated by another memory manager (e.g. GlobalAlloc or CoTaskMemAlloc ).
  • Release an uninitialized pointer. (This distinguishes the release of a null pointer, which is completely safe.)

Somewhere in your program, you are doing one of these things. The debugger detected an exception thrown by the memory manager, so do some debugging. From the stack trace, you should see which variable you are trying to free. Check the rest of your program for other ways to use the variable.

Tools like MadExcept and Eureka Log can help you find errors without errors. They can keep track of where the highlighted pointer was indicated and where it was freed for the first time, and sometimes this is enough information to clarify your mistake and stop releasing things several times.

+9
source share

4th reason for incorrect pointer operation. I had two pointers, where the array [0..1000] of the real and the third pointer, which was the array [1..200] of the real. All 3 pointers that are initialized for i: = from 0 to 1000 do start ptr1 ^ [I]: = 0; ptr2 ^ [I]: = 0; ptr3 ^ [I]: = 0; end; Although this bad program did not bother Pascal in Delphi, calling Dispose from any of the 3 pointers led to the Invalid Pointer Operation. The fix was just to properly initialize the 3rd pointer.

+1
source share

I was caught by this type of "specified error" during debugging of Delphi.

Check if you have any scanned variables with “Allow function calls” enabled or watches that try to show other variables in the same unit (or global) that might be uninitialized. When stopping at a breakpoint, this can cause the Delphi debugger to try to display the value through a function call that accesses an uninitialized pointer or variable. The actual variable that causes the AV file to not be included in your watchlist.

0
source share

All Articles