invalid pointer operation delphi

Использую .dll в своей программе для обработки данных. Абсолютно весь код на Delphi 7 (.dll и программа) .
Функция самая простая в dll:
function InputControl (receive : string):string;
var
buf : string;
i : Integer;
begin
//Является ли команда Enter
i := Pos(‘:’, receive);
buf := Copy(receive, 1, i-1);
if buf = ‘Enter’
then
begin
Result := ‘Команда Enter’;
end;
end;

Но когда написал приложение и через extrenal вызываю библиотеку всё норм, а потом когда использую эту функцию библиотечную, программа выдаёт такую ошибку:
Invalid Pointer Operation
И что это за?!

Вызываю на кнопке:
st := InputControl(‘Enter:GO 123);

Invalid pointer operation В ДЕЛФИ

Я пишу редактор карт для одной из своих игр и при выходе из редактора появлялась ошибка. Оказалась ошибка в модуле, где я загружал картинки в редактор.

Вот код на который стоило обратить внимание:

Нумерация идет с нуля (тоесть последняя цифра динамического массива определеяет нулевой, первый и второй елементы)

for i:=0 to form1.ScrollBar3.Max do

A я пытался что-то в третий записать и ошибки не было. Но при выходе из программы появлялась ошибка

I can’t seem to figure this one out. My program compiles and runs successfully, but during debugging only it pops up a message box saying «Invalid Pointer Operation» when shutting the program down. I have painstakingly checked all the FormCloseQuery and FormDestory events for any syntax or logical error. I found none and they execute as expected without any error.

When I do tell the compiler to break at Invalid Pointer Operation error, it doesn’t do anything but hangs up the program. At which point, I had to terminate or kill the process.

How do you figure this one out?

Thanks in advance,

4 Answers 4

An Invalid Pointer exception is thrown by the memory manager when it tries to free invalid memory. There are three ways this can happen.

The most common is because you’re trying to free an object that you’ve already freed. If you turn on FastMM’s FullDebugMode, it will detect this and point you directly to the problem. (But make sure to build a map file so it will have the information it needs to create useful stack traces from.)

The second way is if you’re trying to free memory that was allocated somewhere other than the memory manager. I’ve seen this a few times when passing a string from a Delphi EXE to a Delphi DLL that wasn’t using the shared memory manager feature.

And the third way involves messing around with pointers directly and probably doesn’t apply to you. If you try to FreeMem or Dispose a bad pointer that doesn’t refer to an actual block of memory allocated by FastMM, you’ll get this error.

It’s most likely the first one. Use FullDebugMode and you’ll find the source of the problem easily.

Invalid pointer operations occur when you tell the Delphi memory manager to release memory that doesn’t belong to it. There are three ways that might happen:

  • Freeing a pointer or object that has already been freed.
  • Using FreeMem to free something that was allocated by some other memory manager (such as GlobalAlloc or CoTaskMemAlloc ).
  • Freeing an uninitialized pointer. (This is distinct from freeing a null pointer, which is completely safe.)

Somewhere in your program, you are doing one of those things. The debugger has detected the exception thrown by the memory manager, so do some debugging. From the stack trace, you should be able to see which variable you’re trying to free. Check the rest of your program for other ways that variable is used.

Tools like MadExcept and Eureka Log can help you find double-free errors. They can keep track of where the pointer in question got allocated and where it was freed the first time, and that is sometimes enough information to figure out your mistake and stop freeing things multiple times.

Оцените статью