Since I have been running in a lot of difficulties when trying to use DLLs, I decided to try out runtime packages (mainly to avoid the memory manager and type registry problems).
From my application I do something like this:
HandleList := TList <THandle>.Create;
try
PackageObj.DoSomething (HandleList);
finally
FreeAndNil (HandleList);
end;
The method (inside the runtime package) just adds something to the list:
procedure TPackageObject.DoSomething (HandleList: TList <THandle>);
begin
HandleList.Clear;
HandleList.Add (0);
end;
I do get Invalid Pointer
exception either in the call to Clear
within the package or in the call to FreeAndNil
in the application. Access violations also happen from time to time.
When using FastMM, it sometimes reports "Block Header has been corrupted".
The error always happens when memory is allocated or freed, i.e. adding something to the list and therefore causing the list to grow dynamically.
Is the way the HandleList
object is passed to the package and back okay? Is there anything important to know about packages and memory management? Or must the error be somewhere else?
EDIT In the case that the error is likely to be somewhere else, how am I supposed to debug something like this? Any experiences?