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

  • SEARCH
  • Home
  • 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 972247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:05:39+00:00 2026-05-16T03:05:39+00:00

This is a question for the generic collection gurus. I’m shocked to find that

  • 0

This is a question for the generic collection gurus.

I’m shocked to find that TList does not override equals. Take a look at this example:

list1:=TList<String>.Create;       
list2:=TList<String>.Create;

list1.Add('Test');
list2.Add('Test');

Result:=list1.Equals(list2);

“Result” is false, even though the two Lists contain the same data. It is using the default equals() (which just compares the two references for equality).

Looking at the code, it looks like the same is true for all the other generic collection types too.

Is this right, or am I missing something??

It seems like a big problem if trying to use TLists in practice. How do I get around this? Do I create my own TBetterList that extends TList and overrides equals to do something useful?
Or will I run into further complications with Delphi generics…… ?

[edit: I have one answer so far, with a lot of upvotes, but it doesn’t really tell me what I want to know. I’ll try to rephrase the question]

In Java, I can do this:

List<Person> list1=new ArrayList<Person>();
List<Person> list2=new ArrayList<Person>();
list1.add(person1);
list2.add(person1);
boolean result=list1.equals(list2);

result will be true. I don’t have to subclass anything, it just works.

How can I do the equivalent in Delphi?

If I write the same code in Delphi, result will end up false.

If there is a solution that only works with TObjects but not Strings or Integers then that would be very useful too.

  • 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-05-16T03:05:39+00:00Added an answer on May 16, 2026 at 3:05 am

    I looked around and found a solution in DeHL (an open source Delphi library). DeHL has a Collections library, with its own alternative List implementation. After asking the developer about this, the ability to compare generic TLists was added to the current unstable version of DeHL.

    So this code will now give me the results I’m looking for (in Delphi):

    list1:=TList<Person>.Create([Person.Create('Test')]);
    list2:=TList<Person>.Create([Person.Create('Test')]);
    
    PersonsEqual:=list1.Equals(list2); // equals true
    

    It works for all types, including String and Integer types

    stringList1:=TList<string>.Create(['Test']);
    stringList2:=TList<string>.Create(['Test']);
    
    StringsEqual:=stringList1.Equals(stringList2); // also equals true
    

    Sweet!

    You will need to check out the latest unstable version of DeHL (r497) to get this working. The current stable release (0.8.4) has the same behaviour as the standard Delphi TList.

    Be warned, this is a recent change and may not make it into the final API of DeHL (I certainly hope it does).

    So perhaps I will use DeHL instead of the standard Delphi collections? Which is a shame, as I prefer using standard platform libraries whenever I can. I will look further into DeHL.

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

Sidebar

Related Questions

It was suggested in this question , that I could cast a generic collection
This is a question about generic c++ event driven applications design. Lets assume that
This is not a specific question but a generic question which was in my
I've seen this question posted here previously but I'm not satisfied that I understand
Just a general curiosity question. Why is this namespace System.Collections.Generic added by default in
This is kind of more generic question, isn't language-specific. More about idea and algorithm
So this is more of a generic question. I seem to keep finding myself
This is a very generic 'best practice' question, but here's an example. Let's say
I think this is likely to be a generic .NET assembly loading question, but
This is more like a good practise question. I want to offer different generic

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.