Results 1 to 2 of 2

Thread: Weird EInvalidPointer Exception

  1. #1

    Weird EInvalidPointer Exception

    Language: Delphi XE

    So I'm trying out some stuff and I run into EInvalidPointer Exception: 'Invalid Pointer Operation'. However I can't find out where I'm doing something wrong.

    Code:
    destructor TPEngine.Destroy;
    var
      Screen: IPScreen;
    begin // <------------ Works up until here
      // Clean up Screens
      while Screens.Count > 0 do
      begin
        Screen := Screens.Last;
        Screens.Remove(Screen);
      end;
      Screens.Free;
    
      inherited;
    end;
    Screens is a List and will always hold at least one Screen. An instance of TPEngine is created in the units initialization section and freed in the finalization section as the last executable code in the program. If there's only one Screen in the Screens list everything works fine. The Exception is raised when I add another screen.
    The debugger gets to the begin keyword in the destructor. If I take one step the exception will be raised.

    As I can see it the exception is raised before my code is executed so I have no idea what causes the exception. Does anyone have an idea what may cause this exception in this case?
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  2. #2
    I'm guessing TPEngine itself was freed already and so would be using code that has no owner.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •