Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:28:07+00:00 2026-06-01T04:28:07+00:00

In Delphi 2009, I had no major problems with Generics so far (using Generics.Collections

  • 0

In Delphi 2009, I had no major problems with Generics so far (using Generics.Collections lists, with no special Generics features).

Now I found this code will cause a ‘Invalid pointer operation’ in the line which accesses MyList.Count. (MyList.Contains and MyList.IndexOf cause the same error).

The error disappears if I declare TMyList = class(TList<TMyEntry>);

Should I avoid TObjectList<T> or is something else in my code causing this error?

type
  TMyEntry = class(TStringlist);
  TMyList = class(TObjectList<TMyEntry>);

procedure TListTests.TestAV;
var
  Entry: TMyEntry;
  MyList: TMyList;
begin
  MyList := TMyList.Create;
  try
    Entry := TMyEntry.Create;
    try
      MyList.Add(Entry);
      Assert(MyList.Count = 1);  // <--- fails
    finally
      Entry.Free;
    end;
  finally
    MyList.Free;
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:28:08+00:00Added an answer on June 1, 2026 at 4:28 am

    TObjectList named Object List because it owns objects wich it stores. so you have not to free objects wich list contains yourself. TObjectList does it for you.
    I’ve tested you example code in Delphi2010. And I get AV in MyList.free() line. the reason is that you do Entry.Free. List doesn’t know about this, and tries to free object again.
    TObjectLists constructor has boolean parametrer ownsObjects (default = true), you can use it and free objects, wich it contains manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is Delphi 2009, so Unicode applies. I had some code that was loading
Using Delphi 2009 and IXMLDOMDocument2 I receive An invalid character was found in text
I have had Delphi 2007 for a while. I tried the Delphi 2009 trial.
I recently upgraded from Delphi 4 to Delphi 2009. With Delphi 4 I had
In Delphi 2009, how can I build a project using command line. I tried
We had the following code prior to Delphi 2009: function MemoryStreamToString(M : TMemoryStream): String;
I'm using Delphi 2009 and the MS Access Interop COM API. I'm trying to
I am using Delphi 2009 and I noticed that there is a macro recorder
I'm using Delphi 2009. In my program, I have been working very hard to
I am using Delphi 2009 with Unicode strings. I'm trying to Encode a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.